Git 基础教程

Git 笔记

git branch 远程分支列表根据最近一次提交时间排序

Git 笔记 Git 笔记


git 远程分支列表如何根据最后一次提交(commit)时间进行排序(升序或降序)?

推荐方法

根据最后一次提交时间降序,命令可如下:

for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r

输出结果如下:

2020-10-11 19:46:26 +0800 3 hours ago 	origin/master
2020-10-10 19:50:14 +0800 27 hours ago 	origin/know
2020-10-10 16:41:42 +0800 30 hours ago 	origin/ledge
2020-10-10 10:59:28 +0800 2 days ago 	origin/dict
2020-10-09 11:33:47 +0800 2 days ago 	origin/staging
2020-09-28 15:31:16 +0800 13 days ago 	origin/fix_bug_1003
2020-09-28 14:36:39 +0800 13 days ago 	origin/develop
2020-09-28 14:32:59 +0800 13 days ago 	origin/fix_bug_0322
2020-09-25 17:35:02 +0800 2 weeks ago 	origin/qa
2020-09-25 15:16:23 +0800 2 weeks ago 	origin/tutorial
2020-09-22 21:58:46 +0800 3 weeks ago 	origin/deep
2020-09-22 20:18:47 +0800 3 weeks ago 	origin/yourknowledge

如果要时间升序,把最后的 sort -r 改为 sort 即可,即去掉 -r 选项。