bash git ls-remote通过正则表达式删除哈希
我有以下命令,该命令使我能够获得以下列表:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用尴尬并使用
/
作为分离器抓住最后一个字段,然后使用SOSSTRING函数从第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:如 >,来自
git ls-remote
的输出良好。我个人使用:对于这种情况,使用
$ TAB
设置为TAB字符(并将所需的URL重新插入到git ls-remote
当然) :但是我喜欢使用名为变量(
\t'$ tab
,$ nl
等)来保持我的白空间字符以进行可读性。对可变名称扩展的需求是为什么对sed
的参数为双引号,而不是我在其他地方使用的更强的单引号,但是在这种情况下,您实际上可以到处使用双引号,或者 -$'...'...'
语法 - 各处的单声引号(但是使用$ $ tab
的变量的另一个原因是$'...'...'...'< /代码>语法可能会产生误导)。
您可以使用文字选项卡字符,而不是扩展变量
$ {TAB}
,也可以在sed命令本身中使用$'...'...'...'...'...'...'...'...'...'...'...'...
但是我喜欢使用名为变量(
$ tab
,$ nl
等)来保持我的白空间字符以进行可读性。对可变名称扩展的需求是为什么对sed
的参数为双引号,而不是我在其他地方使用的更强的单引号,但是在这种情况下,您实际上可以到处使用双引号,或者 -$'...'...'
语法 - 各处的单声引号(但是使用$ $ tab
的变量的另一个原因是$'...'...'...'< /代码>语法可能会产生误导)。
As terrorrussia-keeps-killing noted, the output from
git ls-remote
is well-formatted. I'd personally use:for this case, with
$TAB
set to a tab character (and re-insert desired URL and options into thegit ls-remote
of course):but I like to use named variables (
\t'$TAB
,$NL
, etc.) to hold my white-space characters for readability. The need for variable-name expansion is why the argument tosed
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).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 tosed
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).