我知道我可以这样做:
git diff HEAD^..HEAD
但是是否有一些更容易记忆的缩写,例如:
git diff foo N
N
可以是任意数量的提交,从现在开始计算累积差异?
我知道我可以这样做:
git diff HEAD^..HEAD
但是是否有一些更容易记忆的缩写,例如:
git diff foo N
N
可以是任意数量的提交,从现在开始计算累积差异?
引自 git rev-parse 手册中的 SPECIFYING REVISIONS 章节:
在修订参数后添加 ~<n> 后缀意味着该修订版本的第
<n>
代祖先提交对象,仅遵循第一个父提交对象。
比如,rev~3
相当于rev^^^
,它又相当于rev^1^1^1
。
请参考 git diff
手册中的示例:
git diff HEAD^..HEAD
git diff HEAD^..
git diff HEAD^ HEAD
这些是等效的形式(感谢chrisk在评论中提到了HEAD^..
表达方式)。
它们与git diff HEAD^
不同,因为如Mark Longair所指出的,它会将diff
与工作目录进行比较,而不是上一次提交。
git diff HEAD~15 # diff the working tree with the 15th previous commit
git diff HEAD~15 HEAD # diff the last commit with the 15th previous commit
正如khmarbaise在评论中提到的那样,这应该能够满足您的需求。
git diff HEAD~N
命令可以查看最近 N 次提交与当前工作目录之间的差异。或者使用 git diff HEAD~N..
命令来排除未提交的更改。
git diff HEAD^ HEAD
和git diff HEAD^
不等同 - 后者显示的是HEAD^
和你的工作树之间的更改。我猜测从问题中(虽然不太清楚)他想要git diff HEAD~15 HEAD
。 - Mark Longairref
,它将默认使用HEAD
。因此,git diff HEAD~15..
是一个更简洁的替代方法。 - chrisk