1

I'm looking for any editor or tool that can view side-by-side two different versions of file in a git repository.

There is similar functionality on github, but it only compares the selected version with the previous one and I'd like it to be more flexible (e.g. compare any two versions of the file).

Example Screenshot

  • I'm assuming you want a GUI interface? – Tom Oct 9 '16 at 16:16
  • @Tom yes, I'd like to see the changes highlighted, but if there is commend line solution that is (a) user-friendly, (b) returns clear-formatted output, then why not... – Tim Oct 9 '16 at 16:19
1

By reading your last comment at the time of this writting, you can do this easily with the command line tool called Cdiff. It's usage if pretty simple and works with Git, Mercurial, and SVN. It's written in Python so it runs nicely on Linux.

Cdiff (open source)

Term based tool to view colored, incremental diff in a Git/Mercurial/Svn workspace or from stdin, with side by side and auto pager support. Requires python (>= 2.5.0) and less.

git log -p -2 | cdiff       # view git log with changes of last 2 commits
git show 15bfa | cdiff -s   # view a given git commit, side by side

screenshot

1

Git actually has a command dedicated for this purpose: git difftool. It will open any suitable editor, depending the configuration; in my setup (and, I think, by default) this is vimdiff:

$ git config --global diff.tool
vimdiff

This should be available on any typical Unix system. It doesn't look exactly beautiful (rather a bit too colourful), but it does what you want.

Screenshot of vimdiff invoked from git

And because it's essentially just a special mode of vim, it can also be used very well for editing changesets. For example, when simply executing git difftool, the right-hand view is actually the file in the working directory. So you can easily amend any changes right in this editor, before committing them! (It will by default open both files in readopen mode though, so you actually need :w! to save any changes made in vimdiff.)

Ah, and: to get out of this editor, type :qa. Here, : is the standard vi prefix for ed commands, q is the command for closing (quitting) a file, and the a postfix applies this to all opened files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.