【发布时间】:2011-10-01 14:05:43
【问题描述】:
当我输入 git branch 时,我收到一个分支列表,这些分支似乎按字母顺序排序,而不是按创建时间排序。
有没有办法让git branch 的输出按日期排序?
【问题讨论】:
标签: git git-branch
当我输入 git branch 时,我收到一个分支列表,这些分支似乎按字母顺序排序,而不是按创建时间排序。
有没有办法让git branch 的输出按日期排序?
【问题讨论】:
标签: git git-branch
Stujo's answer 是我最喜欢的,但我想更进一步,按提交者日期排序我的默认 git branch 行为。方法如下:
git config --global branch.sort -committerdate
删除committerdate 之前的- 以另一种方式排序。
现在git branch 将始终按日期排序!
【讨论】:
编辑:从 Git 2.19 版(2018 年末)开始,Git 遵循 branch.sort 配置。从 Git 2.7.0 版本(2016 年初)开始,git branch 本身允许排序,因此您不必直接使用git for-each-ref。
编辑
唉,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)
这会给你一个类似于
的列表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)
_如您所见,在存在许多远程(跟踪)分支的情况下,结果可能有点压倒性,这些分支实际上对相同的修订进行了别名。但是,结果按(降序)日期正确排序。
不,但你应该可以做到
git for-each-ref --sort='-*committerdate' --format="%(refname:short)" refs/heads/
(使用--sort='-*authordate' 进行作者日期排序)
在我的测试存储库中,这会产生:
compress
emmanuel
maint
maint-0.6.9
master
master-lucid
testing
unstable
您可以创建一个 git 别名来执行此操作:将以下行附加到 .git/config
[alias]
branch2 = git for-each-ref --sort='-*committerdate' --format="%(refname:short)" refs/heads/
从那时起,你可以说git branch2
【讨论】:
git branch 的排序。知道可能是什么问题吗?
--sort='-*authordate' 和--sort='-*taggerdate',但它们似乎都没有通过标记时间进行排序。
从 git 2.7.0 开始,这将起作用:
git branch --sort=-committerdate
【讨论】: