Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git diff : compare specific versions of specific file

Tags:

git

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?

like image 799
user1968963 Avatar asked Nov 20 '25 12:11

user1968963


1 Answers

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
like image 161
knittl Avatar answered Nov 23 '25 15:11

knittl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!