I am starting to use Subversion on Linux. svn diff
gives a very cryptic view—very, very unfriendly to eyes. How do I interpret its output? And more importantly, is there a way to view the difference in vimdiff kind of neat style, where both files will open side by side?

- 7,835
- 7
- 61
- 104

- 8,607
- 16
- 66
- 90
9 Answers
Edit the file $HOME/.subversion/config
so it contains the line:
diff-cmd = <your favorite diff application>
Some diff apps support svn. For example, diff-cmd = meld
should work fine. However, vimdiff
is not one of them. The reason for that is that svn diff
gives the files to be compared as 6th and 7th arguments, and not as 1st and 2nd as usual. So what most people do in this situation is this:
Create a wrapper script:
#!/bin/sh
/usr/bin/vimdiff ${6} ${7}
Save it, for example, at $HOME/bin/svndiffwrap.sh
Do not forget to make it executable chmod +x $HOME/bin/svndiffwrap.sh
.
Make it the svn diff command:
in $HOME/.subversion/config
:
diff-cmd = /home/<username>/bin/svndiffwrap.sh
Note: Some svn clients do not support paths that uses $HOME
environment variable. So it is useful to specify full path.

- 16,709
- 6
- 47
- 72

- 14,868
- 16
- 44
- 60
-
1I think this should be the accepted answer because it answers the question directly (rather than providing a link). However, in my case, passing the `--diff-cmd` explicitly, I had to use `${6}` and `${7}` to get the correct behavior. – arr_sea Jul 10 '15 at 18:30
-
2Note that if using `gvimdiff` instead of `vimdiff`, apparently the `--nofork` flag is required: `gvimdiff --nofork ${6} ${7}`. (Without this, the two sides of gvimdiff show up blank.) – arr_sea Jul 10 '15 at 18:31
-
1The `diff-cmd = ...` should go into the `[helpers]` section. – L.R. Nov 04 '16 at 10:01
-
1This is exactly what I want. However, after doing this, I can't get the regularly patches with "svn diff > xxx.patch". So I add the following in svndiffwrap.sh. This is not conveniently anyway, Any other solutions? `patchs="/home/xxx/patchs" mkdir -p /home/xxx/patchs/ NOW=$(date +"%y-%m-%d-%H%M%S") diff "$@" > $patchs/$(basename ${@:$#}).patch.$NOW echo "find svn diff patchs in $patchs"` – samuel Dec 26 '17 at 02:28
-
1@samuel for patches you can also `svn diff --diff-cmd diff > xxx.patch`, this will use diff over vimdiff specifically for this command – Omer Dagan Dec 26 '17 at 09:02
-
I tried using `~` instead of the full path to my home directory, and it didn't work. When I gave the full path, it worked – alexanderbird Mar 09 '18 at 00:04
-
This has a small problem, which is that if you want to make edits to the original file, then you have to specify the full path to save the file (as $7 is a temp file in my version of svn). Have your script be this: `#!/bin/sh f=$(echo ${3}|sed -re 's/ \(revision .*\)$//') /usr/bin/vimdiff ${f} ${6}` – javs May 10 '18 at 22:14
Found it at: http://blog.tplus1.com/index.php/2007/08/29/how-to-use-vimdiff-as-the-subversion-diff-tool/
This blog post takes the script directly from the SVN book external diff tools example:
diffwrap.sh
#!/bin/sh
# Configure your favorite diff program here.
DIFF="/usr/local/bin/vimdiff"
# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT=${6}
RIGHT=${7}
# Call the diff command (change the following line to make sense for
# your merge program).
$DIFF $LEFT $RIGHT
# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.
Note: This assumes that your vimdiff
is in /usr/local/bin
, for me, in Fedora, it was in /usr/bin
. If you can't find it run:
$ whereis vimdiff
Then in ~/.subversion/config
:
[helpers]
...
diff-cmd = /home/<username>/bin/diffwrap.sh
vimdiff <(svn diff)
<()
is referred to as process substitution which creates a pseudo file from the output of svn diff
for vimdiff
to consume.
You can create a shell alias like so: alias svndiff='vimdiff <(svn diff)'
PS - this is the simplest solution I have yet to find; it changed my life (relatively speaking)!
I like having the revision and file in the statusline when using vimdiff with svn so I use the following:
svnvimdiff.sh
#!/bin/bash
/usr/bin/vim -R -d -f --nofork -n -c "let F1='${5//$'\t'/ }' | set statusline=%{F1} | let F2='${3//$'\t'/ }' | setlocal statusline=%{F2}" ${6} ${7}
explanation:
- -R = readonly (we can not edit those files)
- -d = diff mode (side by side)
- -f = foreground (let svn wait)
- --nofork = also foreground (let svn wait)
- -n = skip swapfiles (we do not need the swapfiles since they are already temporary)
- -c = execute vim command
- let F1='${5//$'\t'/ }' (name for all windows with tab replaced because it does not display correctly)
- set statusline=%{F1} (set name as global statusline)
- let F2='${3//$'\t'/ }' (name for first window with tab replaced because it does not display correctly)
- setlocal statusline=%{F2} (set statusline for first window)
Add/change diff-cmd in $HOME/.subversion/config
diff-cmd = /yourpath/svnvimdiff.sh
Or use it inline:
svn diff --diff-cmd /yourpath/svnvimdiff <file>

- 547
- 6
- 7
VCSCommand can do it for you - install the plugin, navigate to the file, and press <Leader>cv

- 12,402
- 5
- 49
- 68
Follow these step
Install colordiff eg: for Ubuntu sudo apt-get install colordiff
Now you can just try svn diff output to colordiff: svn diff -r Rev1:Rev2 file | colordiff
Add following code into your bash profile (~/.bashrc or ~/.bash_profile) to easily access.
svndiff() { svn diff "${@}" | colordiff }
source bash profile.
source ~/.basrc Now it's ready use... You can just see the svn diff in your terminal most effectively.
eg: svndiff

- 1,220
- 14
- 14
Expanding on the answer from xyz above, the following two scripts work perfectly for me:
File /usr/bin/svndiff:
#!/bin/bash
svn diff $@ --diff-cmd=/usr/bin/svndiffwrap.sh
File /usr/bin/svndiffwrap.sh:
#!/bin/bash
/usr/bin/vimdiff ${6} ${7}
Then anything you can do on the command line like:
svn diff -r 124028:125747 ./file1
you can just remove the space and it works as expected:
svndiff -r 124028:125747 ./file1
It even works on entire trees and opens each file in sequence.
svndiff -r 124028:125747 ./directory/

- 41
- 1
- 3
The base of each file is stored in .svn folder so you can write small script to launch vimdiff or mgdiff to give a path in .svn folder against which to compare your file. This won't require you to make vimdiff default diff command for svn.

- 9,187
- 2
- 25
- 19