Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you cancel an external git diff?

I've got vim setup as my external diff tool:

[diff]
        external = git_diff_wrapper

#!/bin/sh

vimdiff "$2" "$5"

Say I have 300 files that have been modified; via bash, I type "git diff". It launches 300 vimdiffs sequentially, how do I abort it?

like image 663
v2k Avatar asked May 07 '10 06:05

v2k


People also ask

How do I terminate Git diff?

To exit this you can use: :q for exit; :h for help; Note: if you don't want to read the output in pager you can use an ENV variable GIT_PAGER to cat or you need to set core.

What is diff tool in Git?

DESCRIPTION. git difftool is a Git command that allows you to compare and edit files between revisions using common diff tools. git difftool is a frontend to git diff and accepts the same options and arguments. See git-diff[1].


2 Answers

Use :cquit to exit vim with an error code. Git will detect the error and stop opening new vimdiffs. You'll probably want to create a mapping for it in your .vimrc:

if &diff
  map Q :cquit<CR>
endif

Then just hit Q to early abort from a git diff run.

In order for this to work you must edit your gitconfig:

git config --global difftool.trustExitCode true
git config --global mergetool.trustExitCode true
like image 197
2 revs, 2 users 70% Avatar answered Sep 20 '22 06:09

2 revs, 2 users 70%


If stopping the process is not enough, killing the shell itself (in which you launched the git diff) might be more effective.

http://trick.vanstaveren.us/wp/wp-uploads/2009/06/close-this-window.png


See also Git Diff with Vimdiff

VimDiff

Not being ready to go full speed into using vimdiff (I’m just new to it), I put the following in ‘gitvimdiff’.
The result is that I can use vimdiff to look at git-diff by running ‘gitvimdiff‘, but a normal invocation of ‘git diff’ behaves as I’m used to.

#!/bin/sh

if [ -n "${GIT_EXTERNAL_DIFF}" ]; then
[ "${GIT_EXTERNAL_DIFF}" = "${0}" ] ||
{ echo “GIT_EXTERNAL_DIFF set to unexpected value” 1>&2; exit 1; }
exec vimdiff “$2″ “$5″
else
GIT_EXTERNAL_DIFF=”${0}” exec git –no-pager diff “$@”
fi

But if you still want the modified git diff, a git status might help before launching it ;)

And you can setup a function to get the old git diff behavior if needed:

I still have access to the default git diff behavior with the --no-ext-diff flag. Here’s a function I put in my bash configuration files:

function git_diff() {
  git diff --no-ext-diff -w "$@" | vim -R -
}
  • --no-ext-diff: to prevent using vimdiff
  • -w: to ignore whitespace
  • -R: to start vim in read-only mode
  • -: to make vim act as a pager
like image 27
VonC Avatar answered Sep 19 '22 06:09

VonC