[英]git diff changed files in x commits of a branch
The task is to output files that have been changed in last 5 commits of the origin/1.5.0
branch. 任务是输出在
origin/1.5.0
分支的最后5次提交中已更改的文件。
Without the branch requirement I came up with: git diff --name-only HEAD~5
. 没有分支要求我想出了:
git diff --name-only HEAD~5
。 With the branch requirement I tried git diff --name-only HEAD~5 --first-parent origin/1.5.0
but the output is longer. 根据分支要求,我尝试了
git diff --name-only HEAD~5 --first-parent origin/1.5.0
但输出更长。 Adding condition shouldn't produce more results which means there's something I don't understand. 添加条件不应该产生更多结果,这意味着我不明白。 Where have I gone wrong?
我哪里出错了?
The git diff
command always 1 compares two commits-or-file-trees. git diff
命令总是1比较两个提交或文件树。 The options and arguments select which two (and how to do the diff, eg, --name-only
or --name-status
skips the patch part of the diff). 选项和参数选择哪两个(以及如何进行diff,例如, -
--name-only
或--name-status
跳过diff的补丁部分)。
If you run git diff HEAD~5
, the two things you selected are: 如果你运行
git diff HEAD~5
,你选择的两件事是:
HEAD~5
: the commit five steps back from HEAD
, the current commit HEAD~5
:从当前提交的HEAD
返回五步 For comparison, if you run git diff --cached HEAD~5
, you select instead HEAD~5
and the current index , and if you run git diff HEAD~10 HEAD~5
you select instead HEAD~10
and HEAD~5
. 为了比较,如果运行
git diff --cached HEAD~5
,则选择HEAD~5
和当前索引 ,如果运行git diff HEAD~10 HEAD~5
,则选择HEAD~10
和HEAD~5
。
Note that the ~ number
syntax comes from gitrevisions . 请注意,
~ number
语法来自gitrevisions 。 A tilde suffix followed by an integer may be applied to any other commit selector, such as a raw hash ID, the name HEAD
, the name of one of your own branches or tags, or the name of any of your remote-tracking branches . 后跟整数的波形符后缀可以应用于任何其他提交选择器,例如原始哈希ID,名称
HEAD
,您自己的分支或标记之一的名称,或任何远程跟踪分支的名称 。 Since origin/1.5.0
is the name of a remote-tracking branch, you can use that to specify the commit to which that name points, or add a tilde and a number to move that many first-parent steps back from that point. 由于
origin/1.5.0
是远程跟踪分支的名称,因此您可以使用它来指定该名称所指向的提交,或者添加波形符和数字以从该点移回许多第一父步骤。
Hence: 因此:
git diff --name-only origin/1.5.0~5 origin/1.5.0
will compare the two specified commits, showing only the names of files that are not the same in those two commits. 将比较两个指定的提交,仅显示这两个提交中不相同的文件的名称。
1 You can make it behave differently in some interesting cases, but they are not the ones we care about here. 1在一些有趣的情况下,你可以使它的行为不同,但它们不是我们在这里关心的。
I think with "origin/1.5.0", the command changed to compare HEAD~5 with the branch origin/1.5.0. 我认为使用“origin / 1.5.0”,命令改为将HEAD~5与分支原点/ 1.5.0进行比较。 That is a much different diff than without branch.
与没有分支相比,这是一个非常不同的差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.