bash git ls-remote通过正则表达式删除哈希

发布于 2025-01-22 01:27:05 字数 470 浏览 3 评论 0原文

我有以下命令,该命令使我能够获得以下列表:

git ls-remote https://github.com/CodeEditApp/CodeEdit --h --sort origin "refs/heads/*"
...
45955931b326913390596b1970ebeb928ccc741e    refs/heads/add-docs-video
4d872980b6a606b9d40c9c3afa5987bbac701fc2    refs/heads/animation-test
c3969f86ea8e332c5b7e63ea8d246d5e7917d475    refs/heads/apple
....

我想在最后获得的结果只是分支名称:

...
add-docs-video
animation-test
apple
....

I have the following command which allows me to get a list like the one below:

git ls-remote https://github.com/CodeEditApp/CodeEdit --h --sort origin "refs/heads/*"
...
45955931b326913390596b1970ebeb928ccc741e    refs/heads/add-docs-video
4d872980b6a606b9d40c9c3afa5987bbac701fc2    refs/heads/animation-test
c3969f86ea8e332c5b7e63ea8d246d5e7917d475    refs/heads/apple
....

the result I would like to get in the end would be just the branch names:

...
add-docs-video
animation-test
apple
....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉城凉梦凉人心 2025-01-29 01:27:05

您可以使用尴尬并使用/作为分离器抓住最后一个字段,然后使用SOSSTRING函数从第3个字段打印该行的其余部分:

yourcommand | awk -F/ '{print substr($0, index($0,$3))}'

You could use awk and grab the last field using / as a separator and then print the rest of the line from the 3rd field using the substring function like so:

yourcommand | awk -F/ '{print substr($0, index($0,$3))}'
风向决定发型 2025-01-29 01:27:05

>,来自git ls-remote的输出良好。我个人使用:

git ls-remote ... 'refs/heads/*' | sed "s,.*${TAB}refs/heads/,,"

对于这种情况,使用$ TAB设置为TAB字符(并将所需的URL重新插入到git ls-remote当然) :

TAB=

您可以使用文字选项卡字符,而不是扩展变量 $ {TAB} ,也可以在sed命令本身中使用 $'...'...'...'...'...'...'...'...'...'...'...'...

... | sed 

但是我喜欢使用名为变量( $ tab $ nl 等)来保持我的白空间字符以进行可读性。对可变名称扩展的需求是为什么对 sed 的参数为双引号,而不是我在其他地方使用的更强的单引号,但是在这种情况下,您实际上可以到处使用双引号,或者 - $'...'...'语法 - 各处的单声引号(但是使用 $ $ tab 的变量的另一个原因是 $'...'...'...'< /代码>语法可能会产生误导)。

\t'

您可以使用文字选项卡字符,而不是扩展变量 $ {TAB} ,也可以在sed命令本身中使用 $'...'...'...'...'...'...'...'...'...'...'...'...


但是我喜欢使用名为变量( $ tab $ nl 等)来保持我的白空间字符以进行可读性。对可变名称扩展的需求是为什么对 sed 的参数为双引号,而不是我在其他地方使用的更强的单引号,但是在这种情况下,您实际上可以到处使用双引号,或者 - $'...'...'语法 - 各处的单声引号(但是使用 $ $ tab 的变量的另一个原因是 $'...'...'...'< /代码>语法可能会产生误导)。

s,.*\trefs/heads/,,

但是我喜欢使用名为变量($ tab$ nl等)来保持我的白空间字符以进行可读性。对可变名称扩展的需求是为什么对sed的参数为双引号,而不是我在其他地方使用的更强的单引号,但是在这种情况下,您实际上可以到处使用双引号,或者 - $'...'...'语法 - 各处的单声引号(但是使用$ $ tab的变量的另一个原因是$'...'...'...'< /代码>语法可能会产生误导)。

\t'

您可以使用文字选项卡字符,而不是扩展变量$ {TAB},也可以在sed命令本身中使用$'...'...'...'...'...'...'...'...'...'...'...'...

但是我喜欢使用名为变量($ tab$ nl等)来保持我的白空间字符以进行可读性。对可变名称扩展的需求是为什么对sed的参数为双引号,而不是我在其他地方使用的更强的单引号,但是在这种情况下,您实际上可以到处使用双引号,或者 - $'...'...'语法 - 各处的单声引号(但是使用$ $ tab的变量的另一个原因是$'...'...'...'< /代码>语法可能会产生误导)。

As terrorrussia-keeps-killing noted, the output from git ls-remote is well-formatted. I'd personally use:

git ls-remote ... 'refs/heads/*' | sed "s,.*${TAB}refs/heads/,,"

for this case, with $TAB set to a tab character (and re-insert desired URL and options into the git ls-remote of course):

TAB=

You can use a literal tab character rather than expanding the variable ${TAB}, or you can use the $'...' syntax in the sed command itself:

... | sed 

but I like to use named variables ($TAB, $NL, etc.) to hold my white-space characters for readability. The need for variable-name expansion is why the argument to sed is in double quotes, vs the stronger single quotes I use elsewhere, but in this case you could in fact use double quotes everywhere, or—with the $'...' syntax—single quotes everywhere (but another reason to use a variable like $TAB is that the $'...' syntax can be misleading).

\t'

You can use a literal tab character rather than expanding the variable ${TAB}, or you can use the $'...' syntax in the sed command itself:


but I like to use named variables ($TAB, $NL, etc.) to hold my white-space characters for readability. The need for variable-name expansion is why the argument to sed is in double quotes, vs the stronger single quotes I use elsewhere, but in this case you could in fact use double quotes everywhere, or—with the $'...' syntax—single quotes everywhere (but another reason to use a variable like $TAB is that the $'...' syntax can be misleading).

s,.*\trefs/heads/,,

but I like to use named variables ($TAB, $NL, etc.) to hold my white-space characters for readability. The need for variable-name expansion is why the argument to sed is in double quotes, vs the stronger single quotes I use elsewhere, but in this case you could in fact use double quotes everywhere, or—with the $'...' syntax—single quotes everywhere (but another reason to use a variable like $TAB is that the $'...' syntax can be misleading).

\t'

You can use a literal tab character rather than expanding the variable ${TAB}, or you can use the $'...' syntax in the sed command itself:

but I like to use named variables ($TAB, $NL, etc.) to hold my white-space characters for readability. The need for variable-name expansion is why the argument to sed is in double quotes, vs the stronger single quotes I use elsewhere, but in this case you could in fact use double quotes everywhere, or—with the $'...' syntax—single quotes everywhere (but another reason to use a variable like $TAB is that the $'...' syntax can be misleading).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文