如何在 Git 中搜索分支名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31787803/
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-09 03:25:47  来源:igfitidea点击:

How do I search for branch names in Git?

gitsearch

提问by user650309

I'd like to find a specific branch, and I know that its name would contain a specific substring (the id of the issue from our bug tracker), but I don't know the whole name of the branch (this is what I want to find out).

我想找到一个特定的分支,并且我知道它的名称将包含一个特定的子字符串(来自我们的错误跟踪器的问题的 id),但我不知道该分支的全名(这就是我想知道)。

How can I search for this branch?

我如何搜索这个分支?

回答by Evil Toad

git branch --all | grep <id>

回答by Calvin Li

Git 1.7.8offers a better solution:

Git 1.7.8提供了更好的解决方案:

git branch --list <pattern>

git branch --list <pattern>

There is no need to go to grep.

没有必要去grep

This works with wildcards (*) as well, so you can do use git branch --list *<id>*to find your branch.

这也适用于通配符 ( *),因此您可以使用它git branch --list *<id>*来查找您的分支。

This filters the list of branch names returned by the rest of your git branchcommand (for example, local branches only by default, all branches with git branch -a --list <pattern>, etc.).

这将过滤由您的git branch命令的其余部分返回的分支名称列表(例如,默认情况下仅本地分支,所有分支都带有git branch -a --list <pattern>,等等)。

回答by Roy Shmuli

git branch -a | grep selector

Or

或者

git branch -r | grep selector

-a shows all local and remote branches, while -r shows only remote branches.

-a 显示所有本地和远程分支,而 -r 仅显示远程分支。

回答by Snekse

Building of the answers that others have given, I added this to my .gitconfig

建立其他人给出的答案,我将此添加到我的 .gitconfig

[alias]
  findb = "!f(){ git branch -ra | grep ; }; f"

So on the command line I can type git findb BUG-123

所以在命令行我可以输入 git findb BUG-123

回答by pawan kumar

Find the branch Name where having specified text

找到指定文本所在的分支名称

git branch --list *text*

For Ex- I want to find the branch that has "production" word

例如,我想找到带有“生产”字样的分支

git branch --list *production*

回答by Fosterdn007

Assuming that you are using GitHub, there is a drop down list for your branches and for tags in that drop down menu there is a search area.

假设您正在使用 GitHub,那么您的分支有一个下拉列表,并且该下拉菜单中的标签有一个搜索区域。

You can use that search area to search for your branch name.

您可以使用该搜索区域来搜索您的分支名称。