【问题标题】:How to list local git branches by order of last visited date如何按上次访问日期的顺序列出本地 git 分支
【发布时间】:2017-01-26 11:03:18
【问题描述】:

我正在寻找一种按@{-1}、@{-2}、@{-3} 等引用的顺序列出 git 分支的方法。 git branch --sort 允许 "authordate" 和 "committerdate" 但找不到类似 "visiteddate" 的内容。

【问题讨论】:

标签: git


【解决方案1】:

我不知道如何找到“上次访问日期”。然而,有一种方法可以按(反向)时间顺序列出分支:


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 使条目具有唯一性,但不必像使用 uniqsort -u 那样对列表进行排序。
  • 感谢awk 的技巧!我使用了一种更复杂的方式(使用cat -n,然后保留唯一的分支名称,然后按行号排序......)
  • 完美答案,它 100% 对我有用。干杯!
猜你喜欢
  • 2020-02-25
  • 1970-01-01
  • 2018-05-08
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-06
  • 2022-01-25
  • 1970-01-01
相关资源
最近更新 更多