ele*_*vir 10
Stujo 的回答是我最喜欢的,但我想更进一步,让按提交者日期排序成为我的默认git branch行为。就是这样:
git config --global branch.sort -committerdate
Run Code Online (Sandbox Code Playgroud)
删除-beforecommitterdate以另一种方式排序。
现在git branch将始终按日期排序!
编辑
唉,所采用的排序选项存在明显的问题git-for-each-ref.由于该命令(显然)明确地旨在显示refs 和接受该--sort选项,我认为这可能是一个错误[1].
这是我可以进一步提出的最佳选择,但输出与原始格式相差甚远(因为它们依赖于事后的装饰修订来引用分支).好吧,也许它对你有用:
[1]如果是这样git-rev-list或者git-log我认为问题是我们实际上并没有走修改树; 我们正在积极尝试只显示树木的提示,而不是走路.
git log --no-walk --date-order --oneline --decorate \
$(git rev-list --branches --no-walk)
Run Code Online (Sandbox Code Playgroud)
这会给你一个类似的列表
4934e92 (HEAD, origin/testing, origin/HEAD, testing) reviewed INSTALL file as per #1331
6215be7 (origin/maint, maint) reviewed INSTALL file as per #1331
1e5e121 (origin/emmanuel, emmanuel) buffers: adjust the size in zfsfuse_stat
e96783e (origin/compress, compress) buffers: adjust the size in zfsfuse_stat
f6e2c6c (origin/unstable, unstable) revert the fatal condition again
dd52720 (origin/master-lucid, master-lucid) lucid
3b32fa7 (tag: 0.7.0, origin/master, master) panic revocation of 0.7.0-0 package necessitates an update
6eaa64f (origin/maint-0.6.9, maint-0.6.9) Replace remount by drop_caches (on rollback)
Run Code Online (Sandbox Code Playgroud)
_正如您所看到的,在存在许多远程(跟踪)分支的情况下,结果可能会有点压倒性,这些分支实际上是对相同的修订进行别名.但是,结果按(降序)日期正确排序.
不,但你应该能做到
git for-each-ref --sort='-*committerdate' --format="%(refname:short)" refs/heads/
Run Code Online (Sandbox Code Playgroud)
(使用--sort='-*authordate'作者日期排序)
在我的测试回购中,这会产生:
compress
emmanuel
maint
maint-0.6.9
master
master-lucid
testing
unstable
Run Code Online (Sandbox Code Playgroud)
你可以创建一个git别名来执行此操作:将以下行追加到 .git/config
[alias]
branch2 = git for-each-ref --sort='-*committerdate' --format="%(refname:short)" refs/heads/
Run Code Online (Sandbox Code Playgroud)
从那以后,你可以说 git branch2
从 git 2.7.0 开始,这将起作用:
git branch --sort=-committerdate
Run Code Online (Sandbox Code Playgroud)