同时允许以后进行相同的合并

同时允许以后进行相同的合并

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

问题描述

还原提交的git merge并保留稍后合并同一分支的选项的最佳方法是什么?

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合并,同时允许以后进行相同的合并)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:57