user1968963
user1968963

Reputation: 2501

Git diff : compare specific versions of specific file

I have cloned linux kernel git repository:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

I am interested in the history of a particular file:

git log net/core/sock_diag.c

I see several commits:

commit 8e904550d0fffcda2b18d7ab12750b0c75757e89
Date:   Sat Feb 23 01:13:48 2013 +0000

commit 6e601a53566d84e1ffd25e7b6fe0b6894ffd79c0
Date:   Sat Feb 23 01:13:47 2013 +0000

commit 9f00d9776bc5beb92e8bfc884a7e96ddc5589e2e
Date:   Sat Sep 8 02:53:54 2012 +0000

How can I diff two particular versions of this file? Lets say, I want to diff the versions from Sep-8 and Feb-23 I could use the following, but that gives me the diffs of the whole commits (not just my file)

git diff 9f00d9776bc5beb92e8bfc884a7e96ddc5589e2e 6e601a53566d84e1ffd25e7b6fe0b6894ffd79c0

could somebody please advise?

Upvotes: 3

Views: 3124

Answers (1)

knittl
knittl

Reputation: 265141

Add the filename to your diff command:

git diff 9f00d9776bc5beb92e8bfc884a7e96ddc5589e2e \
  6e601a53566d84e1ffd25e7b6fe0b6894ffd79c0 -- net/core/sock_diag.c

If you are interested in what changed between commits, you can use git log -p (or --patch):

git log -p net/core/sock_diag.c

Upvotes: 5

Related Questions