Re-use conflict resolution with Git

拟墨画扇 提交于 2020-01-11 02:02:36

问题


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).


For instance, take the following DAG:

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

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.

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 *
* *
*/
*

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


回答1:


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

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


来源:https://stackoverflow.com/questions/23857349/re-use-conflict-resolution-with-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!