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

时间:2011-02-18 07:53:31

标签: git

我知道我能做到:

git diff HEAD^..HEAD

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

git diff foo N

其中N可以是从现在开始的任意数量的提交,以获得累积差异?

2 个答案:

答案 0 :(得分:23)

来自SPECIFYING REVISIONS of the git rev-parse man page

  

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

考虑git diff man page中的示例:

git diff HEAD^..HEAD
git diff HEAD^..
git diff HEAD^ HEAD

是等效表单(感谢HEAD^..表单git diff HEAD^,如评论中所述。)
(它们与diff不等同于chrisk条评论,因为它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 与工作目录,而不是最后一次提交

所以:

{{1}}

应该做你需要的(在评论中提到Mark Longair)。

答案 1 :(得分:7)

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