Git diff分支针对不包含合并的工作树 [英] Git diff branch against working tree not including merges

查看:126
本文介绍了Git diff分支针对不包含合并的工作树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 <$ c $ 

我试图找出当前工作树与另一个分支(例如master)之间的差异。 C>。 --a - > 。 --b - > 。 (主)
\\
c \(合并)
\\
。 -----。 --D - > 。 (当前) - e - > (工作树)

现在, git diff master 确实显示工作树的变化,但是它也显示了master不在当前(-b,c,d,e)的变化。我希望看到这些更改不在master中,也就是我想看到c,d和e。



我试过使用 triple-dot 表示法或使用 git log ,但是这些与提示(最后提交)比较:

  git diff master ... 
git diff master ... current_branch

git log -p --no -merges current..master

返回c和d,即它们不包含e:工作树。



如何得到这个差异来包含工作树?

解决方案

这里要记住的关键点是,如果两个分支共享提交X ,那么不会为diff添加任何内容,也就是说,您没有看到任何有关在diff *中提交X.



因此,您只需要根据分支点进行比较(可以通过 merge- )和$ diff:

$ g $ diff $ git merge-base current master

返回c,d和e。

这也适用如果故事是针对那些看起来更复杂的(有几个合并)的话:

 。 --a  - > 。 --b  - > 。 ---。 (主)
\\ /
c \(合并)/(合并)
\\ /
。 -----。 -----。 --D - > 。 (当前) - e - > (工作树)

返回d和e。

*这解释了为什么您在 git diff master 中看不到 a



我敢打赌,现在要求你感到很傻!


I am trying to find the diff between the current working tree and another branch (e.g. master) not including the merge commits.

. --a--> . --b--> . (master)
 \       \
  c       \ (merge)
   \       \
    . ----- . --d--> . (current) --e--> (working tree)

Now, git diff master does show the working tree changes, however it also shows changes in master not in current (-b, c, d, e). I want to see these changes not in master, that is, I want to see c, d and e.

I've tried using the triple-dot notation or using git log, but these compare against the tip (last commit):

git diff master...
git diff master...current_branch

git log -p --no-merges current..master

returns c and d, i.e. they don't include e: the working tree.

How can I get this diff to include the working tree?

解决方案

The key point to remember here is that if both branches share commit X then this adds nothing to the diff, that is, you don't see anything about commit X in the diff*.

Therefore you only need to diff against the branching point (which you can find with merge-base) and diff against that:

git diff $(git merge-base current master)

returns c, d and e.

This also works if the story is for those which are seemingly more complex (with several merges):

. --a--> . --b--> . --- . (master)
 \       \             /
  c       \ (merge)   / (merge)
   \       \         /
    . ----- . ----- . --d--> . (current) --e--> (working tree)

returns d and e.

* This explains why you don't see a in git diff master.

I bet you feel silly for asking now!

这篇关于Git diff分支针对不包含合并的工作树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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