【发布时间】:2017-01-26 11:03:18
【问题描述】:
我正在寻找一种按@{-1}、@{-2}、@{-3} 等引用的顺序列出 git 分支的方法。 git branch --sort 允许 "authordate" 和 "committerdate" 但找不到类似 "visiteddate" 的内容。
【问题讨论】:
-
定义“已访问”。
标签: git
我正在寻找一种按@{-1}、@{-2}、@{-3} 等引用的顺序列出 git 分支的方法。 git branch --sort 允许 "authordate" 和 "committerdate" 但找不到类似 "visiteddate" 的内容。
【问题讨论】:
标签: git
我不知道如何找到“上次访问日期”。然而,有一种方法可以按(反向)时间顺序列出分支:
git 通过检查 reflog 找出 @{-1}、@{-2}、@{-3} 等,并保持行看起来像 checkout: moving from aaa to bbb。
您可以通过 grep 摆脱相同的行为:
git reflog | grep -o "checkout: moving from .* to " |\
sed -e 's/checkout: moving from //' -e 's/ to $//' | head -20
cmets:
# inspect reflog :
git reflog |\
# keep messages matching 'checkout: ...'
# using -o to keep only this specific portion of the message
grep -o "checkout: moving from .* to " |\
# remove parts which are not a branch (or commit, or anything) name :
sed -e 's/checkout: moving from //' -e 's/ to $//' |\
# keep only last 20 entries
head -20
【讨论】:
git reflog | sed -n 's/.*checkout: moving from .* to \(.*\)/\1/p' | awk '!x[$0]++'。添加为 git 别名!说明:如上,sed 从所有 reflog 行中过滤掉“moving to [X]”。由于某些分支会在此列表中出现多次,因此 awk 使条目具有唯一性,但不必像使用 uniq 或 sort -u 那样对列表进行排序。
awk 的技巧!我使用了一种更复杂的方式(使用cat -n,然后保留唯一的分支名称,然后按行号排序......)