git - 按分支名称对 `git branch --all` 中的分支进行排序

标签 git logging branch

我有一个包含多个 Remote 的存储库。当我发出 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

不起作用,因为本地条目中没有“/”供排序查找。

最佳答案

这可能有点粗糙,但试试这个:

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 - 按分支名称对 `git branch --all` 中的分支进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31023322/

相关文章:

自动确定调用者的类名的 Java 记录器

go - uber-go/zap logger 如何记录到 Kafka 主题?

git - 在不更改工作区文件的情况下切换到另一个分支

eclipse - EGit 检测不到原生 Git 安装路径 "gitPrefix"

git - windows单一开发者易于备份的版本控制

logging - 如何配置log4net SmtpAppender仅在达到特定级别时才向我发送电子邮件?

git - 从远程跟踪分支

Git:分支已经失去了它的历史?

git - 有没有办法让 git-reflog 在每个条目旁边显示日期?

git svn 获取特定目录