Merging in mercurial with vimdiff

Put the lines below in .hg/hgrc file of a repository:
[ui]
merge = vimdiff
[merge-tools]
vimdiff.executable = vim
vimdiff.args = -d $base $local $output $other +close +close

Now whenever you do:
hg pull
hg update
and if there are conflicting changes to be resolved, mercurial will open vim in diff mode with two windows. Left window will show contents of a local file. Right window will show contents of a file being pulled. I usually work in the left window stepping through colored blocks which highlight the conflicts between the two files. When stepping through these blocks I use the two commands below:
:diffget
This command changes the block of code in local file to match corresponding block in pulled file.
:diffput
This command tells mercurial to use block of code in local file for the final version
Each time you navigate to the colored block of code and use one of the above commands, the conflict is resolved and coloring disappears. Repeat this until there are no more conflicts and then quit vim with
: xa
If something goes terribly wrong during merge use
: cq
This command will quit vim telling mercurial that conflicts are not resolved yet. Then repeat with
hg resolve list_files
To see a list of files to be resolved:
hg resolve -l

Advertisements
This entry was posted in Mercurial, Productivity, Programming, UNIX/Linux, Vim. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s