显示直接提交到分支的提交,忽略 Git 中的合并
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8527139/
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
Showing commits made directly to a branch, ignoring merges in Git
提问by Channel Cat
When using git, is there a way to show commits made to a branch, while ignoring all commits that were brought in by merging?
使用 git 时,有没有办法显示对分支的提交,同时忽略通过合并引入的所有提交?
I'm trying to review the code changes made on a branch while ignoring the ones we made on other branches that were merged in. I know it's damn near impossible to show a diff in that fashion, but I'd like to be able to find out which commits I need to review.
我正在尝试在一个分支上所做的代码更改,同时忽略我们在合并的其他分支上所做的更改。我知道以这种方式显示差异几乎是不可能的,但我希望能够找出我需要哪些提交。
回答by CB Bailey
--no-merges
--no-merges
Both parents have equal weight in many contexts in git. If you've always been consistent in merging other changes in then you may find that this gives you what you want.
在 git 中,父母双方在许多情况下都具有相同的权重。如果您在合并其他更改方面一直保持一致,那么您可能会发现这为您提供了想要的东西。
git log --no-merges --first-parent
Otherwise you may be able to exclude commits from other named branches.
否则,您可能能够从其他命名分支中排除提交。
git log --no-merges ^other-branch-1 ^other-branch-2 ^other-branch-3
If you want to review the changes that you are going to merge back into a principal branch then the easiest thing to do is to perform the merge on a local clone and then just look at the diff with the first parent before publishing the merge.
如果您想查看要合并回主分支的更改,那么最简单的方法是在本地克隆上执行合并,然后在发布合并之前查看与第一个父级的差异。
回答by jbochniak
You can use git cherry
for that, it will find you commits that were not yet merged to the upstream, or commits that are on one branch but not the other. So given two branches named "your-branch" and "master":
您可以使用git cherry
它,它会发现您尚未合并到上游的提交,或者在一个分支上但不在另一个分支上的提交。所以给定两个名为“your-branch”和“master”的分支:
git cherry -v your-branch master
will present you list of commits compared with their patch id:
将向您显示提交列表与其补丁 ID 相比:
+ c3e441bf4759d4aa698b4a413f1f03368206e82f Updated Readme
- 2a9b2f5ab1fdb9ee0a630e62ca7aebbebd77f9a7 Fixed formatting
+ e037c1d90b812af27dce6ed11d2db9454a6a74c2 Corrected spelling mistake
You can notice that commits prefixed by "-" are the ones that appear in both branches, whereas those prefixed with "+" are availble only on your branch.
您可以注意到以“-”为前缀的提交是出现在两个分支中的提交,而以“+”为前缀的提交仅在您的分支上可用。
As an alternative you can use:
作为替代,您可以使用:
git log --pretty=format:"%h %s" your-branch..master --no-merges
which will show you list of commits done on "your-branch" that are not yet present on "master"
这将向您显示在“您的分支”上完成但尚未出现在“主”上的提交列表
回答by fge
A very hackish way:
一个非常hackish的方式:
git log --graph --oneline --no-merges thebranch|grep '^\*'
git log --graph --oneline --no-merges thebranch|grep '^\*'