重复使用Git解决冲突 [英] Re-use conflict resolution with Git

查看:109
本文介绍了重复使用Git解决冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以告诉Git重用现有合并提交中的冲突解决方案吗?在提交时,我已经rerere禁用了.新的合并提交在合并的我们的"一侧包含一些其他提交(但它们不应引入新的冲突,因为它们修改了一组不同的文件).

Can I tell Git to re-use the conflict resolution from an existing merge commit? I had rerere disabled at the time of commit. The new merge commit contains a few additional commits on the "ours" side of the merge (but they should not introduce new conflicts as they modified a different set of files).

例如,采用以下DAG:

For instance, take the following DAG:

m [master] Add new stuff
*
| o [old-master] Merge branch A (conflicts)
|/a [branch A]
n *
* *
*/
*

现在,我要执行的操作是将提交mm^放入分支old-master中(然后将其设为新的主文件).我不想简单地将master合并到old-master中,因为它将创建一个新的合并提交(尽管没有冲突).我想用父级ma重新创建提交o.

Now, what I want to do is to bring commits m and m^ into the branch old-master (and later make that the new master). I don't want to simply merge master into old-master, since it will create a new merge commit (albeit without conflicts). I want to recreate commit o with m and a as parents.

新的DAG应该如下所示:

The new DAG should look like:

  p [old-master] Merge branch A (same conflict resolution as old commit o)
 /|
m | [master] Add new stuff
* |
| a [branch A]
n *
* *
*/
*

我不介意使用rerere,如果以后可以告诉它记录现有合并提交(o)的分辨率.

I don't mind using rerere, if I can tell it afterwards to record the resolution of the existing merge commit (o).

推荐答案

实现您要求的最简单方法可能是追溯启用rerere:

The simplest way to implement what you're asking for is probably to retroactively turn rerere on:

git config rerere.enabled true    # with rerere turned on,

git checkout $o^1             # rerun the original merge
git merge $o^2
git read-tree --reset -u $o:  # resolve conflicts exactly as before

git commit                    # throwaway commit to feed the results to rerere

现在,rerere已经看到您对这些冲突做了什么,

and now that rerere has seen what you did with those conflicts,

git checkout -B old-master $o^1   # rewind `old-master` to before the merge
git merge master              # rerun it with current ancestry

这篇关于重复使用Git解决冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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