LoginSignup
4
2

More than 5 years have passed since last update.

Gitのブランチの切り替え(checkout)履歴をpecoる

Last updated at Posted at 2017-05-25

pecoとかxargsとかawkはきっとみんなインストール済みだと思うけど、まだの人はインストールするといいと思う。
fishでしか確認してないけど普通にどのシェルでも動くんじゃないかな。

develop/master は表示除外してるけどそのへんはお好みでどうぞ。

git --no-pager reflog | awk '$3 == "checkout:" && /moving from/ {print $8}' | grep -vE '(develop|master)' | uniq | head -n 20 | peco | xargs git checkout

aliasを適当に設定してね。ぼくは gitcohistory にしてる。

~/.config/fish/config.fish
alias gitcohistory='git --no-pager reflog | awk \'$3 == "checkout:" && /moving from/ {print $8}\' | grep -vE \'(develop|master)\' | uniq | head -n 20 | peco | xargs git checkout'

追記

.gitconfig にセットしたほうがキレイだったのでそうした

.gitconfig
[alias]
    co-history = "!git --no-pager reflog | awk '$3 == \"checkout:\" && /moving from/ {print $8}'" | grep -vE '(develop|master)' | uniq | head -n 20 | peco | xargs git co

参考: http://qiita.com/karupanerura/items/502833d970a7cf93ed96

4
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2