我想要找到一个特定的代码分支,我知道它的名字中包含特定的子字符串(我们的bug追踪器中的问题ID),但是我不知道整个分支的名称(这就是我想找出来的)。
我该如何搜索这个分支?
git branch --all | grep <id>
git branch --all | grep -i <id>
进行筛选所有分支。 - Adam JohnsGit 1.7.8 提供了一种不使用 grep 的解决方案:
git branch --list <pattern>
和在 bash 中加上引号的方式 git branch --list '<pattern>'
。
这同样适用于通配符 (*
),所以你可以使用 git branch --list *<id>*
来查找你的分支。
这会过滤掉由其余git branch
命令返回的分支名称列表(例如,默认情况下仅显示本地分支,使用git branch -a --list<pattern>
显示所有分支等)。
git branch
仅列出本地分支。请使用 git branch -r
列出远程分支,使用 git branch -a
列出所有分支。 - Calvin Ligit checkout -b JIRA-style-test-1 && git branch --list *test*
和git branch --list "*test*"
。只有第二个命令将匹配到JIRA-style-test-1
。请注意,这里的翻译是尽量保持原意并使用通俗易懂的语言,不包含额外解释或其他内容。 - Steven Kaltgit branch -a | grep selector
或者
git branch -r | grep selector
-a选项显示所有本地和远程分支,而-r选项仅显示远程分支。
查找包含指定文本的分支名称
git branch --list *text*
例如- 我想找到包含“production”单词的分支
git branch --list *production*
git branch --list <whatever>
。你写的那个不起作用,如果你没有使用关键字,它会创建一个名为 list 的分支。 - jpenna.gitconfig
中。[alias]
findb = "!f(){ git branch -ra | grep $1; }; f"
所以在命令行中,我可以键入git findb BUG-123
git branch
命令的-l
或--list
选项传递多个模式。所有与模式匹配的分支将被返回。通配符*
可用于匹配名称中包含子字符串的任何分支。-a
或--all
选项。git branch -la "*containsThisSubstring*" "*withThisSuffix" "withThisPrefix*"