Git: List git branches, sort by (and show) date [d

2020-05-12 05:01发布

How can I list git branches showing and sorting by their last commits' dates?

I've found this:

for k in `git branch | sed s/^..//`; do
    echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k"`\\t"$k";
done | sort -r

I'd expect plain git to have this feature. Does it?

I also found git show-branch --date-order but the output is something different.

2条回答
Rolldiameter
2楼-- · 2020-05-12 05:38

I've enjoyed the @Will Sheppard solution to put some colors.

git for-each-ref --sort=committerdate refs/heads/ --format='%(color: red)%(committerdate:short) %(color: cyan)%(refname:short)'
查看更多
走好不送
3楼-- · 2020-05-12 05:42

This appears to be a built-in way to achieve that (v1.7.4):

git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
查看更多
登录 后发表回答