[英]How to get a list of different commits between two git branches?
I want to see a list of only non-common commits between two branches. 我想查看两个分支之间仅非常见提交的列表。
Basically a git diff -y master new-feature
summary between two branches: 基本上是两个分支之间的git diff -y master new-feature
摘要:
master new-feature
-------------------------------------|--------------------------------------
xxx - Jan 1st 2018 - initial commit | xxx - Jan 1st 2018 - initial commit
xxx - Feb 1st 2018 - fix a bug | xxx - Feb 1st 2018 - fix a bug
> xxx - Mar 1st 2018 - WIP almost done
xxx - Apr 1st 2018 - fix another bug | xxx - Apr 1st 2018 - fix another bug
xxx - May 1st 2018 - fix more bugs | xxx - May 1st 2018 - fix more bugs
> xxx - Jun 1st 2018 - Ready to merge!
xxx - Jul 1st 2018 - latest patches <
Solution : I don't know how to make heads or tails of it, but I think git log --graph
accomplishes this, just with a very confusing visual style: 解决方案 :我不知道如何制作它的git log --graph
,但是我认为 git log --graph
做到这一点,只是具有非常令人困惑的视觉风格:
git log --left-right --graph --cherry-pick --oneline master
Better yet, git diff -y --suppress-common-lines master new-feature
is what I really want: 更好的是, git diff -y --suppress-common-lines master new-feature
是我真正想要的:
master new-feature
-------------------------------------|--------------------------------------
> xxx - Mar 1st 2018 - WIP almost done
> xxx - Jun 1st 2018 - Ready to merge!
xxx - Jul 1st 2018 - latest patches <
Solution: You probably can't with git alone but, as per @torek's answer , you can get mostly there with git rev-list
: 解决方案:你可能无法单用git的,但按@托雷克的答案 ,你可以得到大多有与git rev-list
:
git rev-list --left-right master...new-feature
>eb57618eed654685a7999da847628dc5eb27313f
>0da0196ab24542a1a1697b1c0c5efeef6d09e027
>9452f57d97e5fc86e773e7a9fca488b7a0d44a0c
<4fc12fe25a127f8f0dfddf7625c22656c7b2c7c1
<9c0058dcabacfc6560f4fbaf73ea55dd70d27036
>5117fcd041793898683f9469aac00337e9fadd8b
And more critical than that, a git diff --right-only master new-feature
style view would get the job done: 更为关键的是, git diff --right-only master new-feature
样式git diff --right-only master new-feature
视图将完成任务:
commits only in new-feature
-------------------------------------
xxx - Mar 1st 2018 - WIP almost done
xxx - Jun 1st 2018 - Ready to merge!
Which, of course, could be reversed to get the opposite view git diff --right-only new-feature master
当然,可以将其反转以得到相反的视图git diff --right-only new-feature master
commits only in master
-------------------------------------
xxx - Jul 1st 2018 - latest patches
Solution : As @brentjanderson points out , git log master..new-feature
and git cherry -v master
both do this: 解决方案 :正如@brentjanderson指出的那样 , git log master..new-feature
和git cherry -v master
都这样做:
git cherry -v master..new-feature
+ c00335cd93898683f9469aafad8a8476227b117f WIP do things
+ f5c86e777d97e5f3e7a9fca488b79a0d44ac9452 WIP do more
+ 0ef6ddda576180196ab7b1c0c57eefe009e027dc Finished!
as well as 以及
git log master..new-feature --format="%h - %ad - %s" --date=format:'%b %d %Y'
c00335cd - Jan 01 2018 - WIP do things
f5c86e77 - Feb 01 2018 - WIP do more
0ef6ddda - Mar 01 2018 - Finished!
PS I have tried git checkout new-feature; git log --left-right --graph --cherry-pick --oneline master
PS我尝试了git checkout new-feature; git log --left-right --graph --cherry-pick --oneline master
git checkout new-feature; git log --left-right --graph --cherry-pick --oneline master
before, but I can't make heads or tales (or tails) of the output. git checkout new-feature; git log --left-right --graph --cherry-pick --oneline master
,但我无法在输出中显示标题或故事(或git checkout new-feature; git log --left-right --graph --cherry-pick --oneline master
)。 Actually, on second thought, I bet taking the output, turning it sideways, and playing it as excitebike map would make a good tale of it. 实际上,经过深思熟虑,我敢打赌要拿出输出,将其侧向旋转,然后将其作为excitebike地图播放就可以了。 Hmm... 嗯...
Here is a basic variant without fancy formatting: 这是一个没有花哨的格式的基本变体:
git log master..new-feature
You can get "left side" or "right side" data by swapping the order of the branches: 您可以通过交换分支的顺序来获取“左侧”或“右侧”数据:
git log left-side-branch..right-side-branch
This works with other refs (commit hashes, remote branches, tags) too. 这也可以与其他引用(提交哈希,远程分支,标签)一起使用。
To get the full date formatting you want: 要获取完整的日期格式,请执行以下操作:
git log master..new-feature --format="%h - %ad - %s" --date=format:'%b %d %Y'
This doesn't do ordinal dates ( Mar 1st 2018
is Mar 01 2018
) because strftime does not support that. 这不执行序数日期( Mar 1st 2018
Mar 01 2018
Mar 1st 2018
是Mar 1st 2018
Mar 01 2018
),因为strftime不支持该日期。 If that's a hard requirement, I suggest writing a batch script. 如果这是一个困难的要求,我建议编写一个批处理脚本。
I want to see a list of only non-common commits between two branches. 我想查看两个分支之间仅非常见提交的列表。
This is, in set theory, the symmetric difference of the set of commits reachable from branches X and Y. 在集合理论中,这是可从分支X和Y到达的提交集合的对称差 。
This particular set grouping is so useful that it is built into the Git revisions parser, using a syntax described in the gitrevisions documentation , using three dots: X...Y
. 这个特定的集合分组非常有用,以至于它使用gitrevisions文档中描述的语法并使用三个点将其内置到Git版本解析器中: X...Y
How can I get them [formatted in some particular way] 我如何获得它们(以某种特定方式格式化)
Start with git rev-list --left-right master...new-feature
. 从git rev-list --left-right master...new-feature
。 When using the symmetric difference notation, and adding --left-right
, Git will list the commits along with a marker: <
if the commits are reachable from the name on the left but not from the name on the right, or >
if the commits are reachable from the name on the right but not from the name on the left. 当使用对称差异表示法并添加--left-right
,Git将列出提交以及标记: <
如果可以从左边的名称到达提交但不能从右边的名称到达,或者>
如果可以从右侧的名称访问提交,但不能从左侧的名称访问。 Hence: 因此:
git rev-list --left-right master...new-feature
will give you: 会给你:
<aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd
>eeeeeeeeeeffffffffff00000000001111111111
for instance, if commit aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd
exists in master
but not in new-feature
while commit eeeeeeeeeeffffffffff00000000001111111111
exists in new-feature
but not in master
. 例如,如果提交aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd
在master
存在,但在new-feature
不存在,而提交eeeeeeeeeeffffffffff00000000001111111111
在new-feature
但在master
new-feature
不存在。
(Options like cherry-mark
and --left-only
and so on modify or replace the markers to indicate which commits are patch-equivalent, if any, or omit the left or right side, or both. For this case you do not want these.) (诸如cherry-mark
和--left-only
类的选项等会修改或替换这些标记,以指示哪些提交与补丁等效(如果有的话),或者省略左侧或右侧,或者两者都省略。对于这种情况,您不希望这些。)
Having gotten the list from git rev-list
, you can reformat it however you like. 从git rev-list
获得git rev-list
,您可以根据自己的意愿重新格式化。 You can use these same options with git log
but it's generally better to collect the hash IDs first, then deal with the formatting, unless git log
's --pretty=format:...
directives happen to match up with what you need (to find out, see the PRETTY FORMATS section of the git log
documentation ). 您可以在git log
使用这些相同的选项,但是通常最好先收集哈希ID,然后再处理格式,除非git log
的--pretty=format:...
指令恰好与您需要的匹配(要找到答案 ,请参阅git log
文档的PRETTY FORMATS部分 )。
I think running git cherry -v master
on your new-feature
branch should work for the right side. 我认为在new-feature
分支上运行git cherry -v master
应该适用于右侧。 then do the reverse on master for the left side of your list 然后对列表左侧的master进行相反的操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.