git 如何将所有内容回滚到以前的提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22365370/
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-10 17:52:33  来源:igfitidea点击:

How to rollback everything to previous commit

gitgit-commitatlassian-sourcetree

提问by captainrad

Recently in a project with multiple people, a commit was made as seen in the image below. Marked in red you can see a commit with the description/comment of 'Merge?'.

最近在一个多人项目中,进行了一次提交,如下图所示。标记为红色,您可以看到带有“合并?”的描述/评论的提交。

This commit added numerous files and altered numerous others and was never intended to take place.

此提交添加了许多文件并更改了许多其他文件,并且从未打算发生。

Using atlassian-sourcetreewhat do I need to do to roll everything back to the commit highlighted in blue? (I am 8 commits behind as seen in the screenshot.)

使用atlassian-sourcetree我需要做什么才能将所有内容回滚到以蓝色突出显示的提交?(如截图所示,我落后 8 次提交。)

sourcetree troubs

sourcetree 麻烦

回答by 0xcaff

If you have pushed the commits upstream...

如果您已将提交推送到上游...

Select the commit you would like to roll back to and reverse the changes by clicking Reverse File, Reverse Hunkor Reverse Selected Lines. Do this for all the commits after the commit you would like to roll back to also.

选择您想要回滚到的提交并通过单击Reverse FileReverse Hunk或来撤消更改Reverse Selected Lines。对您想要回滚的提交之后的所有提交执行此操作。

reverse stuffreverse commit

反转的东西反向提交

If you have not pushed the commits upstream...

如果您尚未将提交推送到上游...

Right click on the commit and click on Reset current branch to this commit.

右键单击提交并单击Reset current branch to this commit

reset branch to commit

重置分支以提交

回答by Siddhartha Thota

I searched for multiple options to get my git reset to specific commit, but most of them aren't so satisfactory.

我搜索了多个选项来让我的 git 重置为特定的提交,但大多数都不太令人满意。

I generally use this to reset the git to the specific commit in source tree.

我通常使用它来将 git 重置为源树中的特定提交。

  1. select commit to reset on sourcetree.

  2. In dropdowns select the active branch , first Parent Only

  3. And right click on "Reset branch to this commit" and select hard reset option (soft, mixed and hard)

  4. and then go to terminal git push -f

  1. 选择提交以在 sourcetree 上重置。

  2. 在下拉列表中选择活动分支,首先是 Parent Only

  3. 然后右键单击“重置分支到此提交”并选择硬重置选项(软,混合和硬)

  4. 然后转到终端 git push -f

You should be all set!

你应该准备好了!