`git diff topic1 topic2 ^ master`和`git diff topic1..topic2 ^ master`有什么区别? [英] What is the difference between `git diff topic1 topic2 ^master` and `git diff topic1..topic2 ^master`?

查看:128
本文介绍了`git diff topic1 topic2 ^ master`和`git diff topic1..topic2 ^ master`有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图比较在两个不同的提交时从master分出的两个不同分支所做的更改。所以,我不想看到两个分支之间的主人所做的更改。



我试过 git diff topic1 topic2 ^ master git diff topic1..topic2 ^ master ,但是我发现我得到了不同的结果 - 特别是一组不同的更改文件 - 尽管文档说明 git diff ab git diff a..b 是相同的。 ( https://www.git-scm.com/docs/git-diff# _examples



这两个命令之间有什么区别,我可以信任哪一个?或者,我只是做错了吗?有没有更好的方法?

解决方案

修订解析代码 git diff 过分宽容,然后用多个参数结束错误的事情。在某些情况下,如果你给它两个以上的提交ID并且至少其中一个被否定(如你所做的那样),它会错误地解释它的参数。特别是,它会把(positive-ref,positive-ref,negative-ref)三元组视为三点句法。


$ b $几个星期前,我提交了一个专门用于此的Git修复程序,(与往常一样)已被忽略(叹气)。即使有了这个修复,但是,你无法得到你想要的。除了 combined diffs这个更加特殊的情况外,它仍然不是你想要的 - 你只能用Git比较已存在的最多两个现存的树。存储库:


我试图比较在两个不同提交时从master分出的两个不同分支所做的更改。所以,我不希望看到两个分支之间的主人所做的更改。


换句话说,你有一个类似这样的提交图:

  a  -  a  -  A<  -  feature-A 
/
... - o - * - o - o -...< - master
\
b - B < - 特征-B

,您想比较 feature- A -ie,提交 A -to 你会得到,如果你完成了两次提交, code> feature-B (提交 b B )并应用它们到我用 * 标记的提交,即从<$ c $分支特性-A c> master 。



You can 很容易让Git比较commit A 与提交 B 的树。这就是 git diff feature -A feature-B git diff feature -A..feature-B do。但是,这不是你想要的。



为了在提交 A 的树和当前假设的)树 B'您必须创建一个临时分支<1>,然后樱桃挑选两个 feature-B -only提交到 *

  a --a  -  A < -  feature-A 
/
... - o - * - o - o -...< - master
\
\ b - B < - 特征-B
\
b'-B'< - 临时分支

现在你确实有一个提交 B'你拿走了两个中间 master 提交,现在 ,你可以比较 A




1 在技术上可以做到所有这没有一个临时分支,通过构建假设使用 git cherry-pick -n 而不是提交,在工作树中使用cal树 B'一系列使用 git cherry-pick 的临时分支提交。但是,在Git中提交,包括临时分支上的临时分支,速度足够快,价格便宜,以至于不会给你带来太多的收益 - 如果某些挑选步骤需要解决合并冲突,那么这会让所有事情变得更加困难。

I am trying to compare changes that were made on two different branches that forked from master at two different commits. So, I do not want to see the changes that were made on master in-between the two branches.

I have tried git diff topic1 topic2 ^master and git diff topic1..topic2 ^master, but I find that I get different results - specifically, a different set of changed files - despite the fact that the documentation states that git diff a b and git diff a..b are the same. (https://www.git-scm.com/docs/git-diff#_examples)

What is the difference between the two commands, and which one can I trust? Or, am I simply doing this incorrectly? Is there a better way?

解决方案

The revision parsing code for git diff is overly permissive, and then winds up doing the wrong thing with multiple arguments. In some cases it mis-interprets its arguments if you give it more than two commit IDs and at least one of them is negated (as you are doing). In particular, it winds up treating the (positive-ref, positive-ref, negative-ref) triple as if it were the three-dot syntax.

Several weeks ago, I submitted a Git fix specifically for this, which (as usual) has been ignored (sigh). Even with this fix, though, you can't get what you want. Except for the even-more-special case of combined diffs—which still are not what you want—you can only have Git compare at most two existing trees already stored in the repository:

I am trying to compare changes that were made on two different branches that forked from master at two different commits. So, I do not want to see the changes that were made on master in-between the two branches.

In other words, you have a commit graph that goes something like this:

          a--a--A      <-- feature-A
         /
...--o--*--o--o-...    <-- master
               \
                b--B   <-- feature-B

and you want to compare the tip-most commit of feature-A—i.e., commit A—to what you would get if you took the two commits that are exclusively on feature-B (commits b and B) and applied them to the commit I marked with a *, i.e., the point where feature-A branched off from master.

You can quite easily have Git compare the tree for commit A vs the tree for commit B. This is what git diff feature-A feature-B and git diff feature-A..feature-B do. But this is not what you want.

To get a diff between the tree for commit A and a (currently hypothetical) tree B' you must create a temporary branch,1 and then cherry-pick the two feature-B-only commits onto *:

          a--a--A      <-- feature-A
         /
...--o--*--o--o-...    <-- master
         \     \
          \     b--B   <-- feature-B
           \
            b'-B'      <-- temporary branch

Now you really do have a commit B' with the tree that you get if you "take away" the two intermediate master commits, and now you can compare the tree for A against this new commit's tree.


1It is technically possible to do all this without a temporary branch, by constructing the hypothetical tree B' in the work-tree, without committing, using git cherry-pick -n, rather than as a series of commits on a temporary branch using git cherry-pick. But commits in Git, including temporary ones on a temporary branch, are fast enough and cheap enough that this does not buy you much—and if some of the cherry-pick steps require resolving merge conflicts, it just makes everything that much more difficult.

这篇关于`git diff topic1 topic2 ^ master`和`git diff topic1..topic2 ^ master`有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆