tags:

views:

74

answers:

3

On git, how could i compare the same file between two different commits (not contiguos) on the same branch (master for example)?

Is it possible? (i'm searching for a "Compare" feature like the one in VSS or TFS)

+4  A: 
$ git diff $start_commit..$end_commit -- path/to/file

For instance, to see the difference for a file "main.c" between now and two commits back:

$ git diff HEAD^^..HEAD -- main.c
mipadi
The `..` isn't really necessary, though it'll work with it (except in fairly old versions, maybe). You can also use `git log` or `gitk` to find SHA1s to use, should the two commits be very far apart. `gitk` also has a "diff selected -> this" and "diff this -> selected" in its context menu.
Jefromi
+2  A: 

If you want to see all changes to the file between the two commits on a commit-by-commit basis, you can also do

git log -u $start_commit..$end_commit -- path/to/file

cxreg
+2  A: 

You can also compare two different files in two different revisions, like this:

git diff <revision_1>:<file_1> <revision_2>:<file_2>

Jakub Narębski