本文翻译自:How to diff one file to an arbitrary version in Git?
如何将文件(例如pom.xml
)从主分支pom.xml
到Git中的任意旧版本?
#1楼
参考:https://stackoom.com/question/nrgX/如何在Git中将一个文件区分为任意版本
#2楼
If you want to see the difference between the last commit of a single file you can do: 如果您想查看单个文件的最后一次提交之间的区别,您可以执行以下操作:
git log -p -1 filename
This will give you the diff of the file in git, is not comparing your local file. 这将为您提供git中文件的差异,而不是比较您的本地文件。
#3楼
To see what was changed in a file in the last commit: 要查看上次提交中文件中的更改内容:
git diff HEAD~1 path/to/file.
You can change the number (~1) to the n-th commit which you want to diff with. 您可以将数字(~1)更改为要与其进行区分的第n次提交。
#4楼
git diff -w HEAD origin / master path / to / file
#5楼
对于有兴趣从GitHub执行相同操作的人,请参阅跨时间比较提交 。
#6楼
例如,如果您需要在存储区中对单个文件进行区分,则可以执行此操作
git diff stash@{0} -- path/to/file