我怎样才能得到我最近检查过的git分支列表?

Jor*_*ugh 22 git git-checkout git-branch

当我在git分支之间移动时,我有时会忘记我最近在的分支的名称.如何显示最近签出的分支/标签/提交列表?

Jor*_*ugh 40

摘要:

你可以使用git的reflog来显示最近的动作: reflog

脚本:

这是一个可以git reflog从任何git仓库中下载和使用的脚本:https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd

细节:

这基本上是脚本的作用,使reflog输出更有用:

$ git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | awk ' !x[$0]++' | egrep -v '^[a-f0-9]{40}$' | head -n5
master
stable
fix-stuff
some-cool-feature
feature/improve-everything
Run Code Online (Sandbox Code Playgroud)

  • 我使用约旦的要点作为基础,通过从列表中选择一个分支来检查最近的分支:https://gist.github.com/fritz-c/c1e528b09bc1c0827a3c (3认同)

sor*_*oid 5

我的 zshell 中有一个类似的衬垫,它需要一个参数来指定历史记录的长度,默认为 10。

alias bstack='f() { git reflog | grep checkout | cut -d " " -f 8 | uniq | head ${1} | cat -n };f'
Run Code Online (Sandbox Code Playgroud)

例如,列出最后 3 个分支

bstack -3


 1  my-current-branch
 2  my-previous-branch
 3  my-third-most-recent-branch
Run Code Online (Sandbox Code Playgroud)

我从中得出了一些有用的快捷方式

alias bjmp='fn() { bstack ${1} | tail -1 | cut -f 2 | xargs git checkout  }; fn'
Run Code Online (Sandbox Code Playgroud)

允许我从上面的数字中指定要检查的分支

bjmp -3
Run Code Online (Sandbox Code Playgroud)

将签出“我的第三个最近分支”

alias b="bstack -1"
alias bpop="bjmp -2"
Run Code Online (Sandbox Code Playgroud)

对于通过一次击键查看当前分支(尽管这不是最简单的方法)以及仅签出前一个分支也很有用。