Vimdiff and git all at once
Solution 1:
You could use the vim plugins published here. Then you just need to set the difftool:
[multidiff]
tool = vd -f
As an alternative application I would suggest meld
, which will show you modified files - you can then select just the files who's diffs you want to see.
See the screenshot here for an example.
Further to Marcos useful comment, as a third (manual alternative) if you want to use vimdiff
I would recommend following meld
's strategy in a script (possibly python
):
- use
git diff-files --name-status
andgit diff-index --name-status --cached HEAD
to identify files that need to be examined. - Get cached versions of these files and place in
/tmp/
- Open all of these files - the changed files and their cached versions - at once in
vimdiff
- though most likely not possible in the sense that you require- see below.
However, as vimdiff
itself doesn't seem to handle multiple diff tabs natively I recommend one of my other suggestions above.
Solution 2:
A quite simple workaround is to add this option in your ~/.gitconfig file
[difftool]
tool = vimdiff $LOCAL $REMOTE
prompt = true
That way before each file comparison, you are prompted and have the possibility to skip a file by answering 'no' or abort the file comparison with Ctrl+C
Example:
$ git difftool
Viewing: 'file1.js'
Launch 'vimdiff' [Y/n]: y
2 files to edit
Viewing: 'file2.js'
Launch 'vimdiff' [Y/n]: n
Solution 3:
This is what I use. It requires that you use vim-fugitive
[alias]
dt = "!f() { vim -p $(git diff --name-only) +\"tabdo Gdiff $@\" +tabfirst; }; f"
git dt
will then open each diff pair in a separate tab. Then :tabclose
to close a single pair, or :qa
to exit.
source
Solution 4:
There's a much simpler solution that's not posted yet.
Add the following to your ~/.gitconfig
-
[difftool]
trustExitCode = true
Now you can run :cq
at any time during the process to stop diffing more files.
Solution 5:
I came up with the following script to achieve the behaviour git difftoll + vimdiff provides, but using tabs:
#!/bin/bash
commit1=$1
commit2=$2
files=`git diff ${commit1} ${commit2} --name-only`
cmd="set nosplitright | set nobackup | set noswapfile"
EXE="| silent exe"
for f in $files; do
if [ -z "$commit2" ]; then
cmd+="$EXE ':tabnew $f'"
else
cmd+="$EXE ':tabnew | f <${commit2}>/${f} | setlocal buftype=nofile | 0read ! git show ${commit2}:$f'"
fi
cmd+="$EXE ':0 | filetype detect'"
cmd+="$EXE ':vnew | f <${commit1}>/${f} | setlocal buftype=nofile | 0read ! git show ${commit1}:$f'"
cmd+="$EXE ':0 | filetype detect'"
cmd+="$EXE ':windo diffth'"
done
cmd+="$EXE 'bd 1 | tabfirst'"
vim -c "$cmd"
Call it like this:
vimgd <commit1> <commit2>