Git:如何列出此分支上的提交而不是合并分支的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10248137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: How to list commits on this branch but not from merged branches
提问by wch
Suppose your git commit history looks like this:
假设您的 git 提交历史如下所示:
A---B---C---D---E---F master
\ /
X---Y---Z topic
Is it possible to have git list only the commits on master, A-F? In other words, if the commit was on a merged-in branch, I don't want it show.
是否可以让 git 只列出 master 和 AF 上的提交?换句话说,如果提交是在合并的分支上,我不希望它显示。
回答by CharlesB
git log
has option --first-parent
, so you won't get topic
history.
git log
有选项--first-parent
,所以你不会得到topic
历史。
When merged from master
, the master
commits are the first parents in merge. Git log allows to display only those commits with --first-parent, so you get the right stuff.
从 合并时master
,master
提交是合并中的第一个父项。Git log 允许只显示那些带有 --first-parent 的提交,所以你得到了正确的东西。
回答by UpAndAdam
TLDR: git log origin/master --no-merges
will give you a log of master and exclude any merged commits ( in this case x, y, z )
TLDR:git log origin/master --no-merges
将为您提供 master 日志并排除任何合并的提交(在本例中为 x, y, z )
Original Points
原始点
There is another general way to go about this that doesn't rely on --first-parent
which will be helpful in certain situations.. using the branch exclusion filters
还有另一种通用的方法来解决这个问题,它不依赖于--first-parent
在某些情况下会有所帮助..使用分支排除过滤器
git log origin/topic ^origin/master
This will give you a log of origin/topic
with all of origin/master
's commits removed.
git log origin/topic ^origin/master
这将为您提供删除origin/topic
所有origin/master
提交的日志。
you could also add in --no-merges
which will hide merge commits which you may or may not want.
您还可以添加--no-merges
which 将隐藏您可能想要或不想要的合并提交。
Another handy tip is to use shortlog
instead of log
which will give you more of an abbreivated summary that can be handy for release notes, or communication of whats in a branch.
另一个方便的提示是使用shortlog
而不是log
which 会给你更多的简短摘要,这对于发布说明或分支中的内容交流很方便。
Update
After re-reading this, you actually would want nearly the inverse of what I posted; however it would end up excluding everything that is on master and foo ( git log origin/master ^origin/foo
) . However you could also get what you ask for ( hide all commits that are part of merges) with git log origin/master --no-merges
更新
重新阅读本文后,您实际上会想要几乎与我发布的内容相反的内容;但是它最终会排除 master 和 foo( git log origin/master ^origin/foo
) 上的所有内容。但是,您也可以获得所需的内容(隐藏属于合并的所有提交)git log origin/master --no-merges
回答by Stefan Kendall
Does this not work?
这不起作用吗?
git log master
git log --stat master