git识别最近两个分支的交集

jps*_*ain 5 git

是否有用于识别两个分支共同的最后一个提交的简写?例如,如果我有master,然后topic1从master拆分,他们都继续

master:
a------b------c------d
        \
topic1:  r------s------t

有没有办法识别说b
例如,如果存在master#topic1(与topic1#master相同)这样的事情,那就意味着"master和topic共享的最新提交".

我希望能够:

$ git checkout topic1
$ git diff master#topic1..topic1
Run Code Online (Sandbox Code Playgroud)

我知道我能做到:

git diff master..topic
Run Code Online (Sandbox Code Playgroud)

但我不关心提交cd.

Cas*_*bel 7

您实际问的问题的答案:

git diff master...topic
Run Code Online (Sandbox Code Playgroud)

注意三个点.

从联机帮助页:

git diff [--options] <commit>...<commit> [--] [<path>...]

此表单用于查看包含和最多为第二个的分支上的更改,从两者的共同祖先开始<commit>.git diff A...B相当于git diff $(git merge-base A B) B.您可以省略任何一个<commit>,其效果与使用相同HEAD.


J-1*_*DiZ 6

git merge-base.

NAME
git-merge-base - Find as good common ancestors as possible for a merge

SYNOPSIS
git merge-base [-a|--all] [--octopus] <commit> <commit>…
git merge-base --independent <commit>…
Run Code Online (Sandbox Code Playgroud)