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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:31:35  来源:igfitidea点击:

Git: How to list commits on this branch but not from merged branches

gitbranchgit-branchgit-log

提问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 loghas option --first-parent, so you won't get topichistory.

git log有选项--first-parent,所以你不会得到topic历史。

When merged from master, the mastercommits are the first parents in merge. Git log allows to display only those commits with --first-parent, so you get the right stuff.

从 合并时mastermaster提交是合并中的第一个父项。Git log 允许只显示那些带有 --first-parent 的提交,所以你得到了正确的东西。

回答by UpAndAdam

TLDR: git log origin/master --no-mergeswill give you a log of master and exclude any merged commits ( in this case x, y, z )

TLDRgit 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-parentwhich will be helpful in certain situations.. using the branch exclusion filters

还有另一种通用的方法来解决这个问题,它不依赖于--first-parent在某些情况下会有所帮助..使用分支排除过滤器

git log origin/topic ^origin/masterThis will give you a log of origin/topicwith all of origin/master's commits removed.

git log origin/topic ^origin/master这将为您提供删除origin/topic所有origin/master提交的日志。

you could also add in --no-mergeswhich will hide merge commits which you may or may not want.

您还可以添加--no-mergeswhich 将隐藏您可能想要或不想要的合并提交。

Another handy tip is to use shortloginstead of logwhich will give you more of an abbreivated summary that can be handy for release notes, or communication of whats in a branch.

另一个方便的提示是使用shortlog而不是logwhich 会给你更多的简短摘要,这对于发布说明或分支中的内容交流很方便。

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