恢复 git 合并,同时允许稍后进行相同的合并) [英] Reverting a git merge while allowing for the same merge later)

查看:24
本文介绍了恢复 git 合并,同时允许稍后进行相同的合并)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

恢复已提交的 git 合并同时保留稍后合并同一分支的选项的最佳方法是什么?

What's the best way to revert a committed git merge while keeping the option of merging the same branch at a later point?

这是一种情况,当我将一个分支合并到 HEAD 中,然后决定我目前不想要这些更改,但仍然希望在以后的某个时间选择将它们合并到 HEAD.

This is for a situation when I merge a branch into HEAD, then decide that I do not want these changes at the present, but still want the option to merge them into HEAD at some later point.

"git revert -m 1" 将代码恢复到合并前的状态,但分支仍然以某种方式标记为已经合并".因此,稍后与同一分支重复合并是行不通的.

"git revert -m 1" reverts the code to the pre-merge state, but the branch is still somehow marked as "already merged". So a repeated merge with the same branch at a later point does not work.

这应该是一个非常普遍的问题(而且 git 是一个进化的工具),但我找不到一个简单干净的解决方案(除了销毁 git 存储库并再次从远程拉取它).我错过了什么吗?

This should be a very common problem (and git is an evolved tool), yet I cannot find a simple clean solution (apart from destroying the git repository and pulling it from remote again). Am I missing something?

推荐答案

很抱歉,你浪费了你的分支.

Sorry to say that you have wasted your branch.

但是有一个解决方法.诀窍是暂时重写"合并提交,以便它忘记分支是父分支.假设 X 是合并提交:

But there is a workaround. The trick is to "rewrite" the merge commit temporarily so that it forgets that the branch is a parent. Assume X is the merge commit:

git replace --graft X X^   # pretend that there is just one parent
git merge branch           # merge the branch again
git replace --delete X     # remove the replacement

这篇关于恢复 git 合并,同时允许稍后进行相同的合并)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆