当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。
我还没有在diff/log上找到任何明显的选项来提供输出。
当前回答
我喜欢下面的命令来比较特定的提交和上次提交:
git diff <commit-hash>^-
例子:
git diff cd1b3f485^-
其他回答
此命令将获取Git父提交哈希:
git log -n 2 <commit-hash>
之后,gitdiff工具<commithash><parentcommithash>
例子:
bonnie@bonnie ~/ $ git log -n 2 7f65b9a9d3820525766fcba285b3c678e889fe3
commit 7f65b9a9d3820525766fcba285b3c678e889fe3b
Author: souparno <souparno.majumder@gmail.com>
Date: Mon Jul 25 13:17:07 2016 +0530
CSS changed to maintain the aspect ratio of the channel logos and to fit them properly.
commit c3a61f17e14e2b80cf64b172a45f1b4826ee291f
Author: souparno <souparno.majumder@gmail.com>
Date: Mon Jul 25 11:28:09 2016 +0530
The ratio of the height to width of the channel images are maintained.
在此之后
git difftool 7f65b9a9d3820525766fcba285b3c678e889fe3b c3a61f17e14e2b80cf64b172a45f1b4826ee291f
我在windows 10上运行的是Git 2.6.1.windows.1版本,所以我需要对Nevik的答案稍作修改(用波浪号代替插入符号):
git diff COMMIT~ COMMIT
另一个选项是引用插入符号:
git diff "COMMIT^" COMMIT
还可以查看特定文件的两次提交之间的更改。
git diff <commit_Id_1> <commit_Id_2> some_dir/file.txt
检查完整更改:
git diff <commit_Id_1> <commit_Id_2>
仅检查更改/添加/删除的文件:
git diff <commit_Id_1> <commit_Id_2> --name-only
注意:对于检查diff而不在两者之间进行提交,您不需要输入提交id。
从git diff(1)的手册页:
git diff [options] [<commit>] [--] [<path>…]
git diff [options] --cached [<commit>] [--] [<path>…]
git diff [options] <commit> <commit> [--] [<path>…]
git diff [options] <blob> <blob>
git diff [options] [--no-index] [--] <path> <path>
使用中间的第三个:
git diff [options] <parent-commit> <commit>
同样从同一手册页底部的示例部分:
$ git diff HEAD^ HEAD <3>
比较上次提交和上次提交之前的版本。
诚然,它的措辞有点混乱,但也不会那么混乱
将最近的提交与之前的提交进行比较。