我希望能够看到两个分支之间仅包含非公共提交的列表。
我该如何获得像这样的输出?
基本上是两个分支之间的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 <
解决方案: 我不知道如何理解它,但我认为 git log --graph
可以完成这个任务,只是它的可视化效果非常混乱。git log --left-right --graph --cherry-pick --oneline master
还是这个?
更好的选择是,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 <
解决方案: 只使用Git可能无法实现,但是根据@torek的回答,你可以使用git rev-list
,基本上可以实现:
git rev-list --left-right master...new-feature
>eb57618eed654685a7999da847628dc5eb27313f
>0da0196ab24542a1a1697b1c0c5efeef6d09e027
>9452f57d97e5fc86e773e7a9fca488b7a0d44a0c
<4fc12fe25a127f8f0dfddf7625c22656c7b2c7c1
<9c0058dcabacfc6560f4fbaf73ea55dd70d27036
>5117fcd041793898683f9469aac00337e9fadd8b
或者仅仅是这个?
更加关键的是,像 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!
当然,这可以被反转以得到相反的观点git diff --right-only new-feature master
commits only in master
-------------------------------------
xxx - Jul 1st 2018 - latest patches
解决方案:正如@brentjanderson指出的那样,git log main..new-feature
和git cherry -v main
都可以实现这一功能。git cherry -v main
+ 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
,但是我无法理解输出的意义。事实上,仔细想想,我敢打赌把输出结果旋转90度,将其作为excitebike地图玩会很有趣。嗯...