简体   繁体   English

Git diff:比较特定文件的特定版本

[英]Git diff : compare specific versions of specific file

I have cloned linux kernel git repository: 我克隆了linux内核git仓库:

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) 让我们说,我想从9月8日和2月23日区分版本我可以使用以下,但这给了我整个提交的差异(不仅仅是我的文件)

git diff 9f00d9776bc5beb92e8bfc884a7e96ddc5589e2e 6e601a53566d84e1ffd25e7b6fe0b6894ffd79c0

could somebody please advise? 有人可以建议吗?

Add the filename to your diff command: 将文件名添加到diff命令:

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 (或--patch ):

git log -p net/core/sock_diag.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM