Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-use conflict resolution with Git

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

like image 637
knittl Avatar asked May 25 '14 16:05

knittl


People also ask

How do you undo a conflict in git?

On the command line, a simple "git merge --abort" will do this for you. In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.


1 Answers

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
like image 195
jthill Avatar answered Oct 15 '22 11:10

jthill