恢复到 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:43:54  来源:igfitidea点击:

Revert back to specific commit in Git

git

提问by J86

On my Bitbucket Repo, I see this:

在我的 Bitbucket Repo 上,我看到了这个:

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~1will revert to your last commit, while if you want to revert to a specific commit, then use git revert commit_idor in your case you can also use git revert HEAD~2which will roll you back to previous two commits.

在这里,git revert HEAD~1将恢复到您的最后一次提交,而如果您想恢复到特定的提交,则使用git revert commit_id或 在您的情况下,您也可以使用git revert HEAD~2which 将您回滚到前两次提交。