显示直接对分支进行的提交,忽略 Git 中的合并
使用 git 时,有没有办法显示对分支所做的提交,同时忽略通过合并引入的所有提交?
我试图审查在分支上所做的代码更改,同时忽略我们在合并的其他分支上所做的代码更改。我知道以这种方式显示差异几乎是不可能的,但我希望能够找出我需要审查哪些提交。
When using git, is there a way to show commits made to a branch, while ignoring all commits that were brought in by merging?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
--no-merges
在 git 的许多上下文中,父级都具有相同的权重。如果您始终坚持合并其他更改,那么您可能会发现这给了您想要的东西。
否则,您也许可以排除其他命名分支的提交。
如果您想查看要合并回主分支的更改,那么最简单的方法是在本地克隆上执行合并,然后在发布合并之前查看与第一个父级的差异。
--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.
Otherwise you may be able to exclude commits from other named branches.
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.
您可以使用 gitcherry 来实现这一点,它会发现您尚未合并到上游的提交,或者位于一个分支但不在另一个分支上的提交。因此,给定两个名为“your-branch”和“master”的分支:
将向您显示与其补丁 ID 相比的提交列表:
您可以注意到,以“-”为前缀的提交出现在两个分支中,而以“-”为前缀的提交则出现在两个分支中。 “+”仅在您的分支机构可用。
作为替代方案,您可以使用:
这将显示在“您的分支”上完成但尚未出现在“主分支”上的提交列表
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":will present you list of commits compared with their patch id:
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:
which will show you list of commits done on "your-branch" that are not yet present on "master"
一种非常黑客的方式:
git log --graph --oneline --no-merges thebranch|grep '^\*'
A very hackish way:
git log --graph --oneline --no-merges thebranch|grep '^\*'