View git diffs in Emacs using Ediff

The following works for me on Fedora 14 using KDE, git version 1.7.4.2, and GNU Emacs 23.2.1 (x86_64-redhat-linux-gnu, GTK+ Version 2.21.4):

Add the following to your  ~/.gitconfig:


[difftool "ediff"]
cmd = emacs --eval \"(ediff-files \\\"$LOCAL\\\" \\\"$REMOTE\\\")\"
[difftool "ediffclient"]
cmd = emacsclient --eval \"(ediff-files \\\"$LOCAL\\\" \\\"$REMOTE\\\")\"

Then, for example, you can use:


git difftool --tool=ediff --diff-filter=M tagname subdir

to view all the changed files (--diff-filter=M) in the  subdir subdirectory of your working directory relative to the tag  tagname. This will open up a new emacs instance for each diff.

Alternatively, you can use:


git difftool --tool=ediffclient --diff-filter=M tagname subdir

to open the diffs in an existing instance of emacs (assuming you have emacsclient set up). After viewing each diff, you can quit ediff and press ENTER in the terminal you started to get the next diff.

To avoid having to press ENTER, use the  --no-prompt option (although I am not sure how well that will work with the ediffclient version).

The lines in  .gitconfig define a custom diff tool. You can also use other standard diff tools, including kompare (which I sometimes like) and emerge (which is an emacs merge tool, but which I don’t use often):


git difftool --tool=kompare --diff-filter=M tagname subdir
git difftool --tool=emerge --diff-filter=M tagname subdir

See git-difftool for more options.

You can set the default diff tool by adding the following to  .gitconfig:


[diff]
tool = ediffclient

About these ads
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

One Response to View git diffs in Emacs using Ediff

  1. Pingback: A Good Git GUI | What Works For Me

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