git 如何列出包含给定提交的分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1419623/
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
How to list branches that contain a given commit?
提问by Andrew Arnott
How can I query git to find out which branches contain a given commit? gitk
will usually list the branches, unless there are too many, in which case it just says "many (38)" or something like that. I need to know the full list, or at least whether certain branches contain the commit.
如何查询 git 以找出哪些分支包含给定的提交?gitk
通常会列出分支,除非有太多分支,在这种情况下它只会说“很多(38)”或类似的东西。我需要知道完整列表,或者至少某些分支是否包含提交。
回答by VonC
From the git-branch manual page:
git branch --contains <commit>
Only list branches which contain the specified commit (HEAD if not specified). Implies
--list
.
仅列出包含指定提交的分支(如果未指定,则为 HEAD)。暗示
--list
。
git branch -r --contains <commit>
Lists remote tracking branchesas well (as mentioned in user3941992's answerbelow) that is "local branches that have a direct relationship to a remote branch".
还列出远程跟踪分支(如下面user3941992的回答中所述),即“与远程分支有直接关系的本地分支”。
See also this git readyarticle.
另请参阅此git 就绪文章。
The
--contains
tag will figure out if a certain commit has been brought in yet into your branch. Perhaps you've got a commit SHA from a patch you thought you had applied, or you just want to check if commit for your favorite open source project that reduces memory usage by 75% is in yet.
该
--contains
标签将确定某个提交是否已被引入您的分支。也许您已经从您认为已应用的补丁中获得了提交 SHA,或者您只想检查您最喜欢的开源项目的提交是否已将内存使用量减少 75%。
$ git log -1 tests
commit d590f2ac0635ec0053c4a7377bd929943d475297
Author: Nick Quaranto <[email protected]>
Date: Wed Apr 1 20:38:59 2009 -0400
Green all around, finally.
$ git branch --contains d590f2
tests
* master
Note: if the commit is on a remote tracking branch, add the -a
option.
(as MichielBcomments below)
注意:如果提交在远程跟踪分支上,请添加-a
选项。
(正如MichielB在下面的评论)
git branch -a --contains <commit>
MatrixFrogcomments that it only shows which branches contain that exactcommit.
If you want to know which branches contain an "equivalent" commit (i.e. which branches have cherry-picked that commit) that's git cherry
:
MatrixFrog评论说它只显示哪些分支包含确切的提交。
如果你想知道哪些分支包含一个“等效”提交(即哪些分支已经挑选了那个提交),那就是git cherry
:
Because
git cherry
compares the changeset rather than the commit id (sha1), you can usegit cherry
to find out if a commit you made locally has been applied<upstream>
under a different commit id.
For example, this will happen if you're feeding patches<upstream>
via email rather than pushing or pulling commits directly.
因为
git cherry
比较的是变更集而不是提交 id (sha1),您可以使用它git cherry
来确定您在本地所做的提交是否已<upstream>
在不同的提交 id 下应用。
例如,如果您<upstream>
通过电子邮件提供补丁而不是直接推送或拉取提交,则会发生这种情况。
__*__*__*__*__> <upstream>
/
fork-point
\__+__+__-__+__+__-__+__> <head>
(Here, the commits marked '-
' wouldn't show up with git cherry
, meaning they are already present in <upstream>
.)
(在这里,标记为 ' -
'的提交不会出现在 中git cherry
,这意味着它们已经存在于 中<upstream>
。)
回答by Eugen Konkov
You may run:
你可以运行:
git log <SHA1>..HEAD --ancestry-path --merges
From comment of last commit in the output you may find original branchname
从输出中最后一次提交的注释中,您可能会找到原始分支名称
Example:
例子:
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