gpt4 book ai didi

How do I search for branch names in Git?(如何在Git中搜索分支机构名称?)

转载 作者:bug小助手 更新时间:2023-10-27 20:24:09 27 4
gpt4 key购买 nike



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?

我如何才能找到这个分支?


更多回答

hello =] check the link(stackoverflow.com/questions/15292391/…). it can help you.

HELLO=]查看链接(STACKOVERFLOW.com/Questions/15292391/…)。它可以帮助你。

@ThaisaMirely The link you provided is for searching within all files in all branches. This question is asking to just search the branch names.

@ThaisaMirelly您提供的链接用于在所有分支的所有文件中进行搜索。这个问题要求只搜索分支机构名称。

优秀答案推荐

git branch --all | grep <id>


Git 1.7.8 offers a solution without using grep:

Git 1.7.8提供了一个不使用grep的解决方案:


git branch --list <pattern> and in bash git branch --list '<pattern>' with quotes around pattern.

Git分支--list ,在bash git分支中--list‘ ’,模式两边有引号。


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

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


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

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



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仅显示远程分支。



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*


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

在构建其他人给出的答案的基础上,我将此添加到我的.gitconfig中



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


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

因此,我可以在命令行中输入git findb bug-123



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.

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



Multiple pattern can be passed to git branch using the -l or --list option. All branches that match the pattern(s) will be returned. The wildcard * can be used to match any branch that contains a substring in its name.

可以使用-L或--list选项将多个模式传递给git分支。将返回与模式(S)匹配的所有分支。通配符*可用于匹配名称中包含子字符串的任何分支。


To filter on all branches, add the -a or --all option.

要筛选所有分支,请添加-a或--all选项。


For example:

例如:


git branch -la "*containsThisSubstring*" "*withThisSuffix" "withThisPrefix*"

更多回答

git branch --all | grep -i <id> for case insensitivity.

Git BRANCH--all|grep-i表示不区分大小写。

@Evil Toad Your answer seems to be incomplete, because both the above commands give out 3 entries 1 matching branch name, and 2 other matching remote counterparts, how to get the first entry without the asterisk(*) ?

@邪恶Toad你的答案似乎不完整,因为上面的两个命令都给出了3个条目,1个匹配分支机构名称,2个其他匹配的远程对应条目,如何在没有星号(*)的情况下获得第一个条目?

@VickyDev it seems like what you are asking for is not exactly what the OP was asking for. If you require a command to get a different result maybe you should post a new question.

@VickyDev看起来你所要求的并不完全是行动所要求的。如果你需要一个命令才能得到不同的结果,也许你应该发布一个新的问题。

See solution 2 for one that works in Powershell

有关在PowerShell中工作的解决方案,请参阅解决方案2

NOTE: This will only list local branches i.e. you won't be able to find the remote branches with this command.

注意:这将仅列出本地分支机构,即您无法使用此命令找到远程分支机构。

This is because git branch by default, only lists local branches. Use git branch -r for remote branches and git branch -a for all branches.

这是因为默认情况下,git分支只列出本地分支。对远程分支使用git Branch-r,对所有分支使用git Branch-a。

In bash, you're going to need to quote the glob expression to prevent it expanding. To test, try git checkout -b JIRA-style-test-1 && git branch --list *test* vs git branch --list "*test*". Only the second will match JIRA-style-test-1.

在bash中,您需要引用GLOB表达式以防止其扩展。要进行测试,请尝试git check out-b jira-style-test-1&&git Branch--list*test*vs git Branch--list“*test*”。只有第二个匹配JIRA-Style-TEST-1。

@Facepalmed Added to the answer

@facepalmed添加到答案中

can add --all flag to search also remote branches ´git branch --list --all *name*´ bonus it works in Windows Powershell

可以添加--所有标志来搜索远程分支的git分支--列表--所有*名称*‘奖励它在Windows PowerShell中运行

It is git branch --list <whatever>. What you wrote does not work and if you use it without the keyword, it creates a branch named list

它是GIT分支--LIST。您编写的内容不起作用,如果使用时不带关键字,则会创建一个名为List的分支

seems it is just work on local branches, but how about remote branches?

这似乎只是在本地分支机构上工作,但远程分支机构呢?

@Esi add flag --all

@Esi add flag --all

Works fine on remote branches: git branch -r --list *production*

在远程分支上运行良好:GIT BRANCH-r--list*Production*

Although both are using grep on branches list, this one is better than the accepted answer for frequent use. Thank you.

虽然这两种方法都在分支列表上使用grep,但这个方法比公认的频繁使用的答案要好。谢谢。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com