问题描述
是否可以看到我在 git 中使用了哪些分支?
我想在 git 中看到类似分支结帐历史的内容。是否有可能以某种方式做或这种信息不是由 git 存储的?
我无法通过谷歌搜索找到问题的答案。
例如如果我运行命令:git checkout -b feature/foo
,git checkout -b feature/bar
,那么我正在寻找的历史记录中的最后两条记录我希望看到类似于:
...
feature/foo
feature/bar
解决方法
添加到 https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html 的 ElpieKay,来自 comment 的 this gist 可以帮助列出您过去使用过的分支。
它基于Jordan Brough:
BRANCHES=(
$(git reflog |
egrep -io "moving from ([^[:space:]]+)" |
awk '{ print $3 }' | # extract 3rd column
awk ' !x[$0]++' | # Removes duplicates. See http://stackoverflow.com/questions/11532157
egrep -v '^[a-f0-9]{40}$' | # remove hash results
while read line; do # verify existence
([[ $CHECK_EXISTENCE = '0' ]] || git rev-parse --verify "$line" &>/dev/null) && echo "$line"
done |
head -n "$NUM"
)
)
但请记住,reflog 是有时间限制的(默认为 90 天)