13

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

knittl
  • 246,190
  • 53
  • 318
  • 364
  • @jthill: I don't think the other question tries to achieve the same thing. They are not re-doing the merge with conflicts, they are only redoing a merge that came afterwards (and had no conflicts). – knittl May 25 '14 at 19:04
  • Yes, but I want to replace `n` with a new commit `n'` which includes the new commits but has the same conflict resolution (`o` and `p` in my ASCII DAGs) – knittl May 25 '14 at 19:17
  • Sorry for the thrashing, I paid for not having a good blurb up front by misreading my own code. [Is it clearer now what's going on there?](http://stackoverflow.com/a/21952372/1290731) But just turning rerere on and redoing the previous resolution for it is pretty clearly better if rerere's an option. – jthill May 26 '14 at 02:26

1 Answers1

17

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
jthill
  • 55,082
  • 5
  • 77
  • 137