当我执行gitdiffCOMMIT时,我看到了提交和HEAD之间的变化(据我所知),但我希望看到单个提交所做的变化。

我还没有在diff/log上找到任何明显的选项来提供输出。


当前回答

您可以使用git diff HEAD HEAD ^1查看与父提交的差异。

如果您只想查看文件列表,请添加--stat选项。

其他回答

从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>

比较上次提交和上次提交之前的版本。

诚然,它的措辞有点混乱,但也不会那么混乱

将最近的提交与之前的提交进行比较。

Use:

git show <commit_sha>

这将向您展示该承诺中的内容。只需在两个提交SHA-1散列之间放置一个空格,就可以完成范围。

git show <beginning_sha> <ending_sha>

如果您经常重新设置基础,这非常有用,因为您的功能日志都是一行的。

如果您想查看最后3次提交,可以使用HEAD语法

git show HEAD~3 HEAD

如“gitcommit与其父级的差异的速记?”中所述,您也可以将gitdiff用于:

git diff COMMIT^!

or

git diff-tree -p COMMIT

使用gitshow,您需要(为了只关注diff):

git show --color --pretty=format:%b COMMIT

COMMIT参数是COMMIT-ish:

提交对象或可以递归地取消引用到提交对象的对象。以下是所有提交对象:提交对象、指向提交对象的标记对象、指向指向提交对象标记对象的标签对象等。

参见gitrevision“指定修订”以引用提交。另请参阅“tree-ish在Git中是什么意思?”。

另一种可能性:

git log -p COMMIT -1

此命令将获取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