如何获取两个git分支之间的不同提交列表? [英] How to get a list of different commits between two git branches?

查看:122
本文介绍了如何获取两个git分支之间的不同提交列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查看两个分支之间仅非常见提交的列表.

I want to see a list of only non-common commits between two branches.

基本上是两个分支之间的 git diff -y master新功能摘要:

Basically a git diff -y master new-feature summary between two branches:

              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  < 


解决方案:我不知道该怎么做,但是我认为 git log --graph 可以做到这一点,只是具有非常令人迷惑的视觉风格:

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 --left-right --graph --cherry-pick --oneline master











更好的是, git diff -y --suppress-common-lines master new-feature 是我真正想要的:

Better yet, git diff -y --suppress-common-lines master new-feature is what I really want:

              master                               new-feature
-------------------------------------|--------------------------------------
                                     > xxx - Mar 1st 2018 - WIP almost done
                                     > xxx - Jun 1st 2018 - Ready to merge!
xxx - Jul 1st 2018 - latest patches  <


解决方案:您可能无法单独使用git,但根据 @torek的答案,您可以使用 git rev-list 大部分在那里:

Solution: You probably can't with git alone but, as per @torek's answer, you can get mostly there with git rev-list:

git rev-list --left-right master...new-feature

>eb57618eed654685a7999da847628dc5eb27313f
>0da0196ab24542a1a1697b1c0c5efeef6d09e027
>9452f57d97e5fc86e773e7a9fca488b7a0d44a0c
<4fc12fe25a127f8f0dfddf7625c22656c7b2c7c1
<9c0058dcabacfc6560f4fbaf73ea55dd70d27036
>5117fcd041793898683f9469aac00337e9fadd8b











更重要的是, git diff-仅右主新功能样式视图可以完成工作:

And more critical than that, a git diff --right-only master new-feature style view would get the job done:

     commits only in new-feature
-------------------------------------
xxx - Mar 1st 2018 - WIP almost done
xxx - Jun 1st 2018 - Ready to merge!

当然可以将其反转以得到相反的视图 git diff-仅适用于新功能的主版

Which, of course, could be reversed to get the opposite view git diff --right-only new-feature master

       commits only in master               
-------------------------------------
xxx - Jul 1st 2018 - latest patches 


解决方案:正如 @brentjanderson指出的 git log master.新功能 git cherry -v master 都这样做:

Solution: As @brentjanderson points out, git log master..new-feature and git cherry -v master both do this:

git cherry -v master..new-feature

+ c00335cd93898683f9469aafad8a8476227b117f WIP do things
+ f5c86e777d97e5f3e7a9fca488b79a0d44ac9452 WIP do more
+ 0ef6ddda576180196ab7b1c0c57eefe009e027dc Finished!

以及

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!



P.S.我已经尝试过 git checkout new-feature;git log --left-right --graph --cherry-pick --oneline master ,但我无法在输出中显示标题或标题(或结尾).实际上,经过深思熟虑,我敢打赌要拿出输出,将其侧向旋转,然后将其作为excitebike地图播放,这将是一个很好的故事............................................................嗯...

P.S. I have tried 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. 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. 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左侧分支..右侧分支

这也可以与其他引用(提交哈希,远程分支,标签)一起使用.

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'

这不执行顺序日期( 2018年3月1日 2018年3月1日),因为

This doesn't do ordinal dates (Mar 1st 2018 is Mar 01 2018) because strftime does not support that. If that's a hard requirement, I suggest writing a batch script.

这篇关于如何获取两个git分支之间的不同提交列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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