LoginSignup
20
12

More than 5 years have passed since last update.

gitでbranchをcheckoutした履歴

Last updated at Posted at 2016-12-31

作業ログとして、あるいは以前参照したブランチに再度チェックアウトするために、branchをcheckoutした記録を残したいと思ったことはないでしょうか。ぼくはあります。

ぼくは以前まで、 .git/info/.branch.log というファイルを作って .git/hook/post-checkout でブランチ名を記録するといったことを行っていました。

しかし、ちょうどさっきbranchをcheckoutした履歴って実はreflogに含まれてることに気づいてこのオレオレブランチ履歴を捨て去りました。やったね!

git --no-pager reflog | awk '$3 == "checkout:" && /moving from/ {print $8}' | uniq | head

こんな感じでgit自体のログから取れるようになって幸せになりました。

ちなみに、直前に居たブランチにチェックアウトするには:

git checkout -

これでできます。

20
12
2

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
20
12