12

I am trying see how merging in svn can be made easy.

This page mentions that external tools can be used for merging. Can vim be used as the external merge tool?

Some additional requirements:

  1. Files should be split horizontally/vertically to give a better view.
  2. Window titles should be set appropriately.

e.g: as in enter image description here

m.divya.mohan
  • 2,261
  • 4
  • 24
  • 34

1 Answers1

30

Step 1:

Save the following script, e.g: merger.sh:

#!/bin/sh
#


BASE=${1}
THEIRS=${2}
MINE=${3}
MERGED=${4}
WCPATH=${5}

vimdiff $MINE $THEIRS -c ":botright split $MERGED" -c ":diffthis" -c "setl statusline=MERGED | wincmd W | setl statusline=THEIRS | wincmd W | setl statusline=MINE"

Step 2:

Edit .subversion/config and add following line:

merge-tool-cmd = /path/to/merger.sh

Step 3:

When you get following options during svn merge command, select option 'l'. This is to launch external tool to resolve conflicts.

Conflict discovered in 'main.h'.
Select: (p) postpone, (df) diff-full, (e) edit,
        (mc) mine-conflict, (tc) theirs-conflict,
        (s) show all options: l

Step 4: Now vim will be opened in diff mode with 3 files - mine, theirs and merged. Make the required changes in the merged file, and do save and exit (:wqa).

Step 5:

Now below options will appear again, select 'r' (to accept the merged version) now.

Select: (p) postpone, (df) diff-full, (e) edit,
            (mc) mine-conflict, (tc) theirs-conflict,
            (s) show all options: r
icc97
  • 11,395
  • 8
  • 76
  • 90
m.divya.mohan
  • 2,261
  • 4
  • 24
  • 34
  • 1
    If this change is not needed on a permanent basis, it can also be done by setting the environment variable SVN_MERGE=/path/to/merger.sh – Michael Dec 02 '14 at 15:06
  • How might I use this script to resolve a messy workspace with conflicts from an "svn update"? I have a bunch of .r*, .mine files, but not sure how to get my workspace back in a clean state again. – Christopher Feb 16 '16 at 23:25
  • The additions on this answer helped me: http://stackoverflow.com/questions/8312089/how-to-get-external-merge-tools-to-work-with-svn-on-linux – phyatt Apr 06 '16 at 13:45
  • If you meet the error: `The external merge tool exited with exit code 255` after step 3, then `chmod +x merger.sh` – Steven Lee Apr 21 '22 at 17:29