如何查询git以找出哪些分支包含给定的提交? gitk通常会列出分支,除非有太多分支,在这种情况下它只是说“很多(38)”或类似的东西 . 我需要知道完整列表,或者至少是否某些分支包含提交 .
来自git-branch manual page:
git branch --contains <commit>
仅列出包含指定提交的分支(如果未指定,则为HEAD) . 意思是 - 列表 .
git branch -r --contains <commit>
列出 remote tracking branches (如下面user3941992的answer中所述)"local branches that have a direct relationship to a remote branch" .
另见git ready文章 .
--contains标记将确定是否已将某个提交引入您的分支 . 也许你已经从你认为已经应用的补丁中获得了一个提交SHA,或者你只是想检查你最喜欢的开源项目的提交是否已经减少了75%的内存使用量 .
$ git log -1 tests commit d590f2ac0635ec0053c4a7377bd929943d475297 Author: Nick Quaranto <nick@quaran.to> Date: Wed Apr 1 20:38:59 2009 -0400 Green all around, finally. $ git branch --contains d590f2 tests * master
注意: if the commit is on a remote tracking branch, add the -a option .(如MichielB评论below)
git branch -a --contains <commit>
MatrixFrog注释它只显示哪些分支包含该确切提交 .如果你想知道哪些分支包含"equivalent"提交(即哪些分支已经选择了提交),那么 git cherry :
因为git cherry比较了变更集而不是提交标识(sha1),所以你可以使用git cherry来查明你在本地提交的提交是否已在不同的提交id下应用<upstream> . 例如,如果您通过电子邮件提供补丁<upstream>而不是直接推送或提取提交,则会发生这种情况 .
__*__*__*__*__> <upstream> / fork-point \__+__+__-__+__+__-__+__> <head>
(此处,标记为' - ' wouldn' t的提交显示 git cherry ,表示它们已存在于 <upstream> 中 . )
-
git cherry
<upstream>
你可以运行:
git log <SHA1>..HEAD --ancestry-path --merges
从输出中的最后一次提交的注释,您可以找到原始分支名称
例:
c---e---g--- feature / \ -a---b---d---f---h---j--- master git log e..master --ancestry-path --merges commit h Merge: g f Author: Eugen Konkov <> Date: Sat Oct 1 00:54:18 2016 +0300 Merge branch 'feature' into master
2 回答
来自git-branch manual page:
列出 remote tracking branches (如下面user3941992的answer中所述)"local branches that have a direct relationship to a remote branch" .
另见git ready文章 .
注意: if the commit is on a remote tracking branch, add the -a option .
(如MichielB评论below)
MatrixFrog注释它只显示哪些分支包含该确切提交 .
如果你想知道哪些分支包含"equivalent"提交(即哪些分支已经选择了提交),那么 git cherry :
(此处,标记为'
-
' wouldn' t的提交显示git cherry
,表示它们已存在于<upstream>
中 . )你可以运行:
从输出中的最后一次提交的注释,您可以找到原始分支名称
例: