获取最后N次提交的差异的简写?

joa*_*him 17 git

我知道我能做到:

git diff HEAD^..HEAD
Run Code Online (Sandbox Code Playgroud)

但是有一些易于记忆的简写,例如:

git diff foo N
Run Code Online (Sandbox Code Playgroud)

这里N可以是任意数量的提交从现在得到的累积差异?

Von*_*onC 25

手册页SPECIFYING REVISIONSgit rev-parse:

~<n>修订参数的后缀表示提交对象,它是指定提交对象的<n>第三代祖父,仅跟随第一个父对象.
rev~3相当于rev^^^等同于rev^1^1^1.

请考虑git diff手册页中的示例:

git diff HEAD^..HEAD
git diff HEAD^..
git diff HEAD^ HEAD
Run Code Online (Sandbox Code Playgroud)

是等效的形式(感谢chriskHEAD^..表格,如评论中所述).
(他们并不等同于git diff HEAD^,因为马克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
Run Code Online (Sandbox Code Playgroud)

应该做你需要的(正如khmarbaise在评论中提到的那样).


Zaz*_*Zaz 10

使用git diff HEAD~N.或者用于git diff HEAD~N..排除未提交的更改.