回滚 Git 合并
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11722533/
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
Rollback a Git merge
提问by cgmckeever
develop branch
--> dashboard (working branch)
I use git merge --no-ff develop
to merge any upstream changes into dashboard
我git merge --no-ff develop
用来将任何上游更改合并到仪表板中
git log:
git日志:
commit 88113a64a21bf8a51409ee2a1321442fd08db705
Merge: 981bc20 888a557
Author: XXXX <>
Date: Mon Jul 30 08:16:46 2012 -0500
Merge branch 'develop' into dashboard
commit 888a5572428a372f15a52106b8d74ff910493f01
Author: root <[email protected]>
Date: Sun Jul 29 10:49:21 2012 -0500
fixed end date edit display to have leading 0
commit 167ad941726c876349bfa445873bdcd475eb8cd8
Author: XXXX <>
Date: Sun Jul 29 09:13:24 2012 -0500
The merge had about 50+ commits in it, and I am wondering how to just revert the merge so dashboard goes back to the state pre-merge
合并中有大约 50 多个提交,我想知道如何恢复合并以便仪表板回到合并前的状态
The second part of this is, if I dont do merge with --no-ff
, I don't get the commit 'Merge branch 'develop' into dashboard' .. How would I roll that merge back?
第二部分是,如果我不与 合并--no-ff
,我不会提交'合并分支'开发'到仪表板'..我将如何回滚该合并?
回答by Christopher
Reverting a merge commit has been exhaustively covered in other questions.When you do a fast-forward merge, the second one you describe, you can use git reset
to get back to the previous state:
其他问题已经详尽地介绍了恢复合并提交。当您进行快进合并时,您描述的第二个合并,您可以使用git reset
它返回到之前的状态:
git reset --hard <commit_before_merge>
You can find the <commit_before_merge>
with git reflog
, git log
, or, if you're feeling the moxy (and haven't done anything else): git reset --hard HEAD@{1}
你可以找到<commit_before_merge>
with git reflog
, , git log
, 或者,如果你感到莫名其妙(并且没有做任何其他事情):git reset --hard HEAD@{1}
回答by sturrockad
From here:
从这里:
http://www.christianengvall.se/undo-pushed-merge-git/
http://www.christianengvall.se/undo-pushed-merge-git/
git revert -m 1 <merge commit hash>
Git revert adds a new commit that rolls back the specified commit.
Git revert 添加一个回滚指定提交的新提交。
Using -m 1 tells it that this is a merge and we want to roll back to the parent commit on the master branch. You would use -m 2 to specify the develop branch.
使用 -m 1 告诉它这是一个合并,我们希望回滚到主分支上的父提交。您将使用 -m 2 来指定开发分支。
回答by Nico Erfurth
Just reset the merge commit with git reset --hard HEAD^
.
只需使用git reset --hard HEAD^
.
If you use --no-ff git always creates a merge, even if you did not commit anything in between. Without --no-ff git will just do a fast forward, meaning your branches HEAD will be set to HEAD of the merged branch. To resolve this find the commit-id you want to revert to and git reset --hard $COMMITID
.
如果您使用 --no-ff git 总是会创建一个合并,即使您没有在两者之间提交任何内容。如果没有 --no-ff git 只会快速前进,这意味着您的分支 HEAD 将被设置为合并分支的 HEAD。要解决此问题,请找到您要恢复的提交 ID 和git reset --hard $COMMITID
。
回答by Jorge Orpinel
git revert -m 1 88113a64a21bf8a51409ee2a1321442fd08db705
But may have unexpected side-effects. See --mainline parent-number
option in git-scm.com/docs/git-revert
但可能有意想不到的副作用。请参阅git-scm.com/docs/git-revert 中的--mainline parent-number
选项
Perhaps a brute but effective way would be to check out the left parent of that commit, make a copy of all the files, checkout HEAD
again, and replace all the contents with the old files. Then git will tell you what is being rolled back and you create your own revert commit :) !
也许一种粗暴但有效的方法是检出该提交的左父级,复制所有文件,HEAD
再次检出,然后用旧文件替换所有内容。然后 git 会告诉您回滚的内容,然后您创建自己的还原提交 :) !