以下命令有什么区别?:
git diff foo master # a
git diff foo..master # b
git diff foo...master # c
差异手册是这么说的:
比较分支 $ git diff topic master <1> $ git diff topic..master <2> $ git diff topic…< 3 >大师 主题提示和主分支之间的变化。 同上。 自主题分支从主分支启动以来发生在主分支上的更改。
但我不太清楚。
以下命令有什么区别?:
git diff foo master # a
git diff foo..master # b
git diff foo...master # c
差异手册是这么说的:
比较分支 $ git diff topic master <1> $ git diff topic..master <2> $ git diff topic…< 3 >大师 主题提示和主分支之间的变化。 同上。 自主题分支从主分支启动以来发生在主分支上的更改。
但我不太清楚。
当前回答
git diff foo master
将显示在那个时间点上的foo和master分支之间的差异
git diff foo..master
还将显示foo分支和master分支在该时间点之间的差异(相当于上面的内容)。
git diff foo...master
将显示从主分支创建foo分支时与之后的所有差异。
因此,前两个命令是相同的,最后一个命令显示了不同历史的更广泛视图。
其他回答
我的综合版本。对…用diff和log
由于我已经创建了这些图像,我认为它可能值得在另一个答案中使用它们,尽管之间的差异的描述。(点-点)和…(点-点-点)和manojlds的答案本质上是一样的。
git diff命令通常只显示提交图中两个点之间树状态的差异。. .和…git diff中的符号有以下含义:
# Left side in the illustration below:
git diff foo..bar
git diff foo bar # same thing as above
# Right side in the illustration below:
git diff foo...bar
git diff $(git merge-base foo bar) bar # same thing as above
In other words, git diff foo..bar is exactly the same as git diff foo bar; both will show you the difference between the tips of the two branches foo and bar. On the other hand, git diff foo...bar will show you the difference between the "merge base" of the two branches and the tip of bar. The "merge base" is usually the last commit in common between those two branches, so this command will show you the changes that your work on bar has introduced, while ignoring everything that has been done on foo in the mean time.
这就是你所需要知道的关于…和…git中的符号是不同的。
... 这里一个常见的困惑来源是…和…当在命令中使用时,例如git log,它期望一组提交作为一个或多个参数。(这些命令最终都使用git rev-list从它们的参数解析提交列表。)
的意义。和…对于git日志可以如下图所示:
git rev-list foo. bar会显示分支bar上没有在分支foo上的所有内容。另一方面,git rev-list foo…Bar会显示所有在foo或Bar中提交的文件,但不会同时显示。第三个图显示,如果列出两个分支,就会得到其中一个或两个分支中的提交。
好吧,我发现这一切都有点混乱,无论如何,我认为提交图表有帮助:)
¹我只说“典型”,因为在解决合并冲突时,例如,git diff会向你展示一个三向合并。
上面的图等价于下面的图树
A0 <- A1 <- A2 <- A3 (master)
\
C0 <- C1 (test)
一图胜千言,差.. ...^如下所示。
$ git log master..test
# output C0 C1
$ git log ^master test
# output C0 C1
$ git log master…test
# output A1 A2 A3 C0 C1
git diff foo master提示(头部)和master之间的差异。
做同样事情的另一种方式。
Git diff foo…master区别于foo和master的共同祖先(git merge-base foo master)到master的尖端。换句话说,它只显示了主分支自它与foo的共同祖先以来所引入的更改。
这个学习。GitHub“合并会引入什么”的例子(存档)解释了什么时候使用这两个:
For instance, if you create a ‘dev’ branch and add a function to a file, then go back to your ‘master’ branch and remove a line from the README, and then run something like this: $ git diff master dev It will tell you that a function was added from the first file and a line was added to the README. Why? Because on the branch, the README still has the original line, but on ‘master’ you’ve removed it - so directly comparing the snapshots looks like ‘dev’ added it. What you really want to compare is what ‘dev’ has changed since your branches diverged. To do that, Git has a nice little shorthand: $ git diff master...dev
git diff foo master
将显示在那个时间点上的foo和master分支之间的差异
git diff foo..master
还将显示foo分支和master分支在该时间点之间的差异(相当于上面的内容)。
git diff foo...master
将显示从主分支创建foo分支时与之后的所有差异。
因此,前两个命令是相同的,最后一个命令显示了不同历史的更广泛视图。