简体   繁体   English

通过分支名称在`git branch --all`中分支

[英]Order branches in `git branch --all` by branch name

I have a repository with multiple remotes. 我有一个包含多个遥控器的存储库。 When I issue a git branch --all --verbose it shows: 当我发出一个git branch --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

In this output it's hard to see, if every local branch is on par with its remote counterparts. 在这个输出中,很难看出,如果每个本地分支都与其远程对手相提并论。 I'd fancy an output ordered by local branch name: 我喜欢按本地分支名称排序的输出:

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

This way, skimming over the output to see unpushed changes would be much easier on the eye. 这样,浏览输出以查看未按下的更改将更容易在眼睛上。 A naive solution 一个天真的解决方案

git branch -a -v | sort -t / -k 3

doesn't work, because the local entries have no "/" in them for sort to look for. 不工作,因为当地的条目没有“/”,在他们的sort寻找。

This might be a little rough, but try this: 这可能有点粗糙,但试试这个:

git branch --all --verbose | sed 's/^[ *] //' | while read line; do echo $(basename $(echo $line | awk '{ print $1 }')) $line; done | sort | cut -d' ' -f2-

Basically, we extract the basename of the branch, giving us only the branchname without the remotes/origin/whatever . 基本上,我们提取分支的basename ,只给我们没有remotes/origin/whatever的branchname。 We then sort by it, then cut it off of the final output via cut . 然后我们按它排序,然后通过cut将其从最终输出中cut This can be tweaked and cleaned up, but it should give you a starting point. 这可以调整和清理,但它应该给你一个起点。 You can also add --color to the initial git branch to preserve the colored output you'd see without piping git to anything. 您还可以将--color添加到初始git branch以保留您看到的彩色输出,而无需使用git to任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM