【发布时间】:2021-02-24 01:01:26
【问题描述】:
我读过 git reset commitBeforeDoingMerge --hard 不会撤消合并:
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 有问题:
通常您无法还原合并,因为您不知道哪一边 的合并应该被认为是主线。该选项指定 主线的父编号(从 1 开始)并允许还原 反转相对于指定父级的更改。
还原合并提交声明您永远不会想要树 合并带来的变化。结果,以后的合并只会 引入由非祖先的提交引入的树更改 先前还原的合并。这可能是也可能不是您想要的。
那么,有没有办法干净而轻松地撤消 git 合并?
【问题讨论】:
-
git reset --hard将撤消合并。 (总是干净利落)但我认为你应该澄清你是如何得到“合并”的,因为合并应该至少有两个平行的分支而不是你的单行。 -
@ian 我更新了问题,也许现在更清楚了。 Git reset --hard 会将您带到该快照,但不会撤消对历史记录所做的更改。
标签: git git-merge git-reset git-revert