按分支名称在`git branch--all`中订购分支
我有一个带有多个遥控器的存储库。当我发出一个按分支名称在`git branch--all`中订购分支,git,logging,branch,Git,Logging,Branch,我有一个带有多个遥控器的存储库。当我发出一个git分支--all--verbose时,它显示: bar 9876de11 hello world foo 12abde23 description master 34fd4545 tony the pony quz ab34df67 me, too remotes/origin/bar 9876d
git分支--all--verbose时,它显示:
bar 9876de11 hello world
foo 12abde23 description
master 34fd4545 tony the pony
quz ab34df67 me, too
remotes/origin/bar 9876de11 hello world
remotes/origin/foo 12abde23 description
remotes/origin/master 34fd4545 tony the pony
remotes/origin/quz ab34df67 me, too
remotes/zulu/bar 9876de11 hello world
remotes/zulu/foo 12abde23 description
remotes/zulu/master 34fd4545 tony the pony
remotes/zulu/quz ab34df67 me, too
在这个输出中,很难看到,如果每个本地分支与它的远程分支保持一致。我希望输出按本地分支名称排序:
bar 9876de11 hello world
remotes/origin/bar 9876de11 hello world
remotes/zulu/bar 9876de11 hello world
foo 12abde23 description
remotes/origin/foo 12abde23 description
remotes/zulu/foo 12abde23 description
master 34fd4545 tony the pony
remotes/origin/master 34fd4545 tony the pony
remotes/zulu/master 34fd4545 tony the pony
quz ab34df67 me, too
remotes/origin/quz ab34df67 me, too
remotes/zulu/quz ab34df67 me, too
通过这种方式,浏览输出以查看未经压缩的更改将更加容易。天真的解决办法
git branch -a -v | sort -t / -k 3
不起作用,因为本地条目中没有“/”可供sort
查找。这可能有点粗糙,但请尝试以下方法:
git branch --all --verbose | sed 's/^[ *] //' | while read line; do echo $(basename $(echo $line | awk '{ print $1 }')) $line; done | sort | cut -d' ' -f2-
基本上,我们提取分支的basename
,只提供分支名称,而不提供remotes/origin/whatever
。然后,我们对其进行排序,然后通过cut
将其从最终输出中删除。这可以调整和清理,但它应该给你一个起点。您还可以将--color
添加到初始的git分支
,以保留您看到的彩色输出,而无需将git
添加到任何内容。也许您可以使用git为每个ref
执行此操作,但这可能很棘手;特别是,远程跟踪分支及其相应的本地分支可能没有相同的名称。这很有趣!我已经玩了一点,但还没有想出一个像样的解决方案。不过,看起来很有希望。哈<代码>基本名称
!真是个好主意!不过,我不得不稍微调整一下:git branch--all--verbose | sed的/^[*]/'|在读行时;do echo$(basename$(echo$行| awk'{print$1}'))$行;完成|排序|切割-d'-f2-
。基本上,删除--color
,因为绿色条目将在红色条目之前找到,而sed的/^[*]/'
将删除活动分支的前导标记。太棒了,谢谢:)错误地包含了--color,我只是想在下面的解释中添加它。删除当前分支指示符的要点很好。我编辑了我的答案以包含您的更改。