我如何区分一个文件,比如pom.xml,从主分支到Git中的任意旧版本?


当前回答

如果你需要区分一个单独的文件在藏匿,例如,你可以这样做

git diff stash@{0} -- path/to/file

其他回答

要查看上次提交文件中修改了什么:

git diff HEAD~1 path/to/file

您可以将数字(~1)更改为您想要区别对待的第n个提交。

git diff -w HEAD origin/master path/to/file
git diff master~20 -- pom.xml

如果你不在主分支也有效。

如果你正在寻找特定提交的差异,并且你想使用github UI而不是命令行(比如你想将它链接到其他人),你可以这样做:

https://github.com/<org>/<repo>/commit/<commit-sha>/<path-to-file>

例如:

https://github.com/grails/grails-core/commit/02942c5b4d832b856fbc04c186f1d02416895a7e/grails-test-suite-uber/build.gradle

请注意右上角的Previous和Next链接,它们允许您浏览提交中的所有文件。

不过,这只适用于特定的提交,而不适用于任意两个版本之间的比较。

git diff <revision> <path>

例如:

git diff b0d14a4 foobar.txt