我读过执行 git reset commitBeforeDoingMerge --hard 不会撤消 merge :
1pm-3pm This is my branch and I need to merge master into it
1pm-2pm This was master
1pm-2pm-3pm-4pm Merging ended up doing this, 4pm being the merge commit
1pm-2pm-3pm if This is the result if you do git reset 3pm --hard, because it does not undo the merge, it just goes back to that commit in the branch that was merged.
现在,另一个建议是执行 git revert 4pm -m 1,但根据 manual 这有问题:
Usually you cannot revert a merge because you do not know which side of the merge should be considered the mainline. This option specifies the parent number (starting from 1) of the mainline and allows revert to reverse the change relative to the specified parent.
Reverting a merge commit declares that you will never want the tree changes brought in by the merge. As a result, later merges will only bring in tree changes introduced by commits that are not ancestors of the previously reverted merge. This may or may not be what you want.
那么,有没有一种方法可以干净、轻松地撤消 git merge ?
最佳答案
I've read that doing git reset commitBeforeDoingMerge --hard would no undo the merge
无论你在哪里读到它,它都是错误的。这正是撤消 merge 的方法。
假设您要 merge branch
进入master
.所以我们在 merge 之前有这个:
A -- B -- C (master)
\
X -- Y (branch)
好的,所以我们 git checkout master
和 git merge branch
.结果是:
A -- B -- C -- D (master)
\ |
X -- Y (branch)
...其中 D 是 merge 提交,C 和 Y 是其父级。
如果你现在说 git reset --hard <SHA-of-C>
,你回到了这个:
A -- B -- C (master)
\
X -- Y (branch)
这是一个完美的撤销。
关于git - 有没有一种方法可以干净轻松地撤消 git merge?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64796878/