[英]How to return to a commit in detached branch
I was using a detached branch without know it, then i used git commit -m <commit_name> .我在不知道的情况下使用了一个分离的分支,然后我使用了 git commit -m <commit_name> 。
Here the problem: I returned to a previous branch and when I wanted to return to what I had done, i couldn't find the branch or commit问题在这里:我回到了以前的分支,当我想回到我所做的事情时,我找不到分支或提交
git reflog
at rescue. git reflog
在救援时重新登录。 Unreachable commits - those not reachable via any branch or tag - can still be checkout
ed, as they are still in the local repository (at least during sometime, if git gc
is not invoked).无法访问的提交——那些无法通过任何分支或标签访问的提交——仍然可以被checkout
编辑,因为它们仍然在本地存储库中(至少在某个时候,如果git gc
未被调用)。
You can locate the hash of your lost commit, the one committed in detached mode, inspecting the reflog:您可以找到丢失提交的 hash,即以分离模式提交的提交,检查 reflog:
git reflog
Once you locate it, do:找到它后,请执行以下操作:
git checkout <hash_of_lost_commit>
And then create a new branch normally:然后正常创建一个新分支:
git checkout -b my_new_branch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.