如何在 git 中撤消结帐?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3601911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I undo a checkout in git?
提问by Yuval Karmi
I just checked out an earlier commit from my local git repo. I haven't made any changes to it, I was just looking at it. Now I want to go back to my latest commit - how do I do that?
我刚刚从我的本地 git repo 中查看了一个较早的提交。我没有做任何改变,我只是看着它。现在我想回到我最近的提交 - 我该怎么做?
The exact command I used to check it out:
我用来检查它的确切命令:
git checkout e5dff6b3c5d704f9b598de46551355d18235ac08
Now when I type git log, at the top I see this checked out commit, but none of my later commits. Did I accidentally delete those?
现在,当我输入 git log 时,在顶部我看到这个已检出的提交,但我后来没有提交。我不小心删除了那些?
回答by Amber
Try this first:
先试试这个:
git checkout master
(If you're on a different branch than master
, use the branch name there instead.)
(如果您在与 不同的分支上master
,请改用那里的分支名称。)
If that doesn't work, try...
如果这不起作用,请尝试...
For a single file:
对于单个文件:
git checkout HEAD /path/to/file
For the entire repository working copy:
对于整个存储库工作副本:
git reset --hard HEAD
And if that doesn't work, then you can look in the reflog to find your old head SHA and reset to that:
如果这不起作用,那么您可以查看 reflog 以找到旧的头部 SHA 并重置为:
git reflog
git reset --hard <sha from reflog>
HEAD
is a name that always points to the latest commit in your current branch.
HEAD
是一个始终指向当前分支中最新提交的名称。
回答by Gaylord Thankyou Johnson
To undo git checkout
do git checkout -
, similarly to cd
and cd -
in shell.
要撤消git checkout
做git checkout -
,类似于cd
和cd -
壳。
回答by wuputah
You probably want git checkout master
, or git checkout [branchname]
.
您可能想要git checkout master
, 或git checkout [branchname]
。