4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitで最近触ったブランチのリストを出す

Posted at

正確にはコミット日時で並び替えたブランチのリストを出す方法です。

git --no-pager branch --sort=committerdate

--no-pagerでページャーを抑制。--sort=committerdateで並び替えます。--sort=-committerdateと頭に-を入れると降順で並び替えられます。

これをaliasに登録しようと思ったら--no-pagerを登録するのには一ひねり必要なようです。下記でいけました。

$ vi ~/.gitconfig

[alias]
        recent-branch = !git --no-pager branch --sort=committerdate

一つ前に戻るのは

git checkout -

で可能ですが、2,3個のブランチを行ったり来たりしてる時、正確なスペルが思い出せない時重宝します。

参考サイト

https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
https://stackoverflow.com/questions/48341920/git-branch-command-behaves-like-less
https://qiita.com/oieioi/items/d8c48012ca3a1ecb274d

4
3
0

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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?