我有一个包含多个遥控器的存储库。当我发出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
在这个输出中,如果每个本地分支与其远程对应分支相同,则很难看到。我喜欢按本地分支名称排序的输出:
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
寻找。
答案 0 :(得分:1)
这可能有点粗糙,但试试这个:
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 branch
,以保留您看到的彩色输出,而不会将git
发送到任何内容。