恢复到 Git 中的特定提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41427441/
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
Revert back to specific commit in Git
提问by J86
On my Bitbucket Repo, I see this:
在我的 Bitbucket Repo 上,我看到了这个:
I would like to get back to where I was when I made that commit with an arrow pointing to it.
我想回到我用箭头指向它时提交的位置。
In my commit where I removed AutoMapper, I removed many files and folders and I know want them all back. I want all to be same as before when I made the 44f31d5commit.
在我删除 AutoMapper 的提交中,我删除了许多文件和文件夹,我知道希望它们都回来。当我进行44f31d5提交时,我希望所有内容都与以前相同。
I thought this would be common, so I tried all sorts from posts I found on SO (you can see my attempt) and this didn't work! I got that last commit by doing
我认为这很常见,所以我尝试了在 SO 上找到的各种帖子(你可以看到我的尝试),但这没有用!我得到了最后一次提交
git revert HEAD~1
And committing. I was thinking that would revert my last commit, instead I revert the second (if that makes sense).
并承诺。我在想这会恢复我的最后一次提交,而不是我恢复第二次(如果这是有道理的)。
采纳答案by Niki
Here, git revert HEAD~1
will revert to your last commit, while if you want to revert to a specific commit, then use git revert commit_id
or in your case you can also use git revert HEAD~2
which will roll you back to previous two commits.
在这里,git revert HEAD~1
将恢复到您的最后一次提交,而如果您想恢复到特定的提交,则使用git revert commit_id
或 在您的情况下,您也可以使用git revert HEAD~2
which 将您回滚到前两次提交。