首页/开发/Git 与协作速查/分支列表排序

分支列表排序

git branch --sort 按提交日期、作者等排序,配合 -v 显示最新提交;巡检时快速发现长期未动的分支。

Git 与协作速查开发更新于 2026-10-12
常用排序--sort=-committerdate(按提交时间倒序)
组合-v/-vv 附带提交信息与跟踪状态
扩展for-each-ref --format 自定义输出

常用示例

常用示例
git branch --sort=-committerdate
git branch -vv --sort=-committerdate | head
git branch -r --sort=-committerdate | head
把「按提交日期排序」列入每周巡检,能直观看到需要收尾或被遗弃的分支。

易错点

  • 排序键是提交时间,作者机器时钟偏差会打乱次序
  • 超长分支列表配 -v 输出变宽,终端窄时截断合理使用 head

数据来源与参考

  • Git 官方文档:git-branch(--sort)
  • Git 官方文档:git-for-each-ref
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌