git reset --soft 并返回到最新的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11479626/
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
git reset --soft and going back to the latest commit
提问by xonegirlz
So I just did a git --reset soft to go back to a previous commit. Now what if I want to go back to the latest commit that I was at before? i.e: the latest commit? I tried doing git log, but the commit listed there didn't have the latest commit.
所以我只是做了一个 git --reset soft 回到以前的提交。现在如果我想回到我之前的最新提交怎么办?即:最新的提交?我尝试做 git log,但那里列出的提交没有最新的提交。
回答by Jon O.
git reset
is the wrong tool to use if you just want to go back and look at an old commit, since in many modes it actually alters the history by removing commits, as you've discovered.
git reset
如果您只想返回并查看旧提交,则是错误的工具,因为在许多模式下,正如您所发现的那样,它实际上通过删除提交来改变历史记录。
If you want to temporarily get an old commit back in your working tree, just use git checkout
. In this case, git checkout HEAD^
will take you back one commit. git checkout HEAD~3
will take you back three commits, and so on. Or you can give it the hash from git log
.
如果您想暂时在工作树中恢复旧提交,只需使用git checkout
. 在这种情况下,git checkout HEAD^
将带您返回一次提交。git checkout HEAD~3
将带您返回三个提交,依此类推。或者您可以从git log
.
You can then return to the latest commit by doing git checkout master
(replacing master
with the name of any branch).
然后,您可以通过执行git checkout master
(替换master
为任何分支的名称)返回到最新提交。
回答by Frank Sposaro
Do you want to basically undo your reset? It's not going to show up in your git log because you reverted it from that. However it will show up in your
您想基本上撤消您的重置吗?它不会出现在你的 git 日志中,因为你从那里恢复了它。但是它会出现在你的
git reflog
This will give you a listing of all your different branches.
这将为您提供所有不同分支的列表。
git reset HEAD@{1}
Should fix your problem if your reset was the last thing you did.
如果您的重置是您做的最后一件事,则应该解决您的问题。