Table of Contents


This will show you how to configure git with emerge and how to use emerge to resolve git merge conflicts. Emerge can be thought of as an industrial strength merge-conflict resolution tool, and is especially useful when merging a large new change with an existing commit or branch.

Configure git

This will make emerge your default mergetool

>> git config --global merge.tool emerge  

Resolve merge conflicts with 'mergetool'

When you have a conflict arise after a git-pull, for example here my .gitignore has a merge conflict.

>> git pull
Auto-merging .gitignore
CONFLICT (content): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

Fire up the mergetool right after this with

  >> git mergetool

Normal merge conflict for '.gitignore':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (emerge): 

Using Emerge

Fast Mode

The default mode for resolving conflicts in emerge is called "fast-mode" and is indicated by a capital F in the minor mode list. For this mode, each difference, or conflict, is represented in the main buffer by

 text that differs

The top two buffers represent the two versions of this file that differ. The left is 'A', and the right is 'B'. For any of the differences, hit a or b to select that version as the correct one to substitute for the difference. Use n 'next' and p 'previous' to cycle through the differences in a file. At the end of your session, just save the file and quit.

Edit Mode

Sometimes, simply selecting one version or the other isn't enough, and you need to manually merge the two by editing the file. To do this, you need to enter 'edit mode' which is done by hitting the E key. Once in edit mode, all the shortcuts mentioned in 'fast-mode' above no longer apply, but all the usual Emacs shortcuts and commands are now back. Use edit mode to manually fix the difference, then get back into fast mode using the command C-c C-c f.

Author: Mishal Awadah

Date: 2012-11-14 17:49:50 EST

HTML generated by org-mode 7.3 in emacs 24