Teaching git to (rerere)resolve Merge Conflicts

Reuse Recorded Resolution

If only I knew about this sooner.  After repeatedly resolving the same merge conflicts over and over while merging in long-lived feature branches, I found rerere. Rerere saves your merge resolutions and automatically reapplies them the next time you encounter the same conflicts.  Once enabled it works behind the scenes without you needing to change the way you work.

To enable:

$ git config --global rerere.enabled true

Then merge in feature branch:

$ git checkout origin/dev
$ git merge feature/a
...
CONFLICT (content): Merge conflict in path/to/file
...
Automatic merge failed; fix conflicts and then commit the result.

Resolve the merge conflict and commit.

$ git add path/to/file
$ git commit

Then if feature/a wasn't ready and you have to back it out, the next time you merge feature/a into dev the merge conflict will be automatically resolved based on the previously recorded resolution.

$ git reset --hard origin/dev
$ git merge feature/a
...
CONFLICT (content): Merge conflict in path/to/file
...
Resolved 'path/to/file' using previous resolution.
Automatic merge failed; fix conflicts and then commit the result.

You can then review the file if you want and then add and commit the results.

$ git add path/to/file
$ git commit

If for some reason you need to delete the recorded resolution you can use:

$ git rerere forget path/to/file

Next time you merge you will need to resolve the conflicts manually.