签出之前的提交后如何返回到最新的提交? [英] How to get back to the latest commit after checking out a previous commit?
问题描述
我有时会查看一些以前版本的代码来检查或测试.如果我想修改以前的提交,我已经看到了如何做的说明——但假设我没有做任何更改.在我完成后,例如git checkout HEAD^
,我如何回到分支的顶端?.. git log
不再显示最新提交的 SHA.
I sometimes check out some previous version of the code to examine or test. I have seen instructions on what to do if I wish to modify previous commits -- but suppose I make no changes. After I've done e.g. git checkout HEAD^
, how do I get back to the tip of the branch?.. git log
no longer shows me the SHA of the latest commit.
推荐答案
如果你知道你想要返回的提交是某个分支的头部,或者被标记,那么你可以
If you know the commit you want to return to is the head of some branch, or is tagged, then you can just
git checkout branchname
您还可以使用 git reflog
来查看您的 HEAD(或任何其他引用)过去指向的其他提交.
You can also use git reflog
to see what other commits your HEAD (or any other ref) has pointed to in the past.
编辑添加:
在较新版本的 Git 中,如果你只运行 git checkout
或其他东西来移动你的 HEAD
一次,你也可以这样做
In newer versions of Git, if you only ran git checkout
or something else to move your HEAD
once, you can also do
git checkout -
切换回上次结帐之前的位置.这是由于类似于 shell 习语 cd -
返回到之前所在的任何工作目录.
to switch back to wherever it was before the last checkout. This was motivated by the analogy to the shell idiom cd -
to go back to whatever working directory one was previously in.
这篇关于签出之前的提交后如何返回到最新的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!