LoginSignup
2

More than 5 years have passed since last update.

gitのブランチ名を時間順(新しい順)に並べて一覧する

Last updated at Posted at 2015-02-11

参考: Show git branches by date - useful for showing active branches

上のサイトのものをアレンジして、aliasに登録

.gitconfig
[alias]
  brt = "! f() { for k in $(git branch -r $@ | sed 's/^..//; s/ .*//'); do  echo "$(git log -1 --pretty='%Cgreen%ci %Cblue(%cr)%Creset ' $k) $k" ;  done | sort -r; }; f"
  blt = "! f() { for k in $(git branch $@ | sed 's/^..//; s/ .*//'); do  echo "$(git log -1 --pretty='%Cgreen%ci %Cblue(%cr)%Creset ' $k) $k" ;  done | sort -r; }; f"

実行結果

リモートのブランチ一覧 (brt)

$ git brt
2015-02-11 11:21:00 +0100 (43 minutes ago) origin/master
2015-02-11 11:21:00 +0100 (43 minutes ago) origin/HEAD
2015-02-11 08:41:44 +0100 (3 hours ago) origin/4-2-stable
2015-02-11 01:46:58 -0800 (77 minutes ago) origin/use-kwards-in-benchmark
2015-02-10 08:56:38 -0700 (19 hours ago) origin/4-1-stable
2015-01-29 14:38:45 -0200 (13 days ago) origin/3-2-stable
2015-01-18 23:36:57 -0500 (3 weeks ago) origin/better_minitest_runner
2015-01-10 16:00:17 -0800 (4 weeks ago) origin/fix_nested_transactions_for_realz
2015-01-06 17:09:25 -0300 (5 weeks ago) origin/4-0-stable

ローカルのブランチ一覧 (blt)

$ git blt
g blt
warning: refname 'v3.2.14' is ambiguous.
2015-02-11 11:21:00 +0100 (49 minutes ago) master
2013-07-22 12:05:41 -0300 (1 year, 7 months ago) v3.2.14

類似の投稿
http://qiita.com/yocifico/items/6e58480baa2bf696148d
http://qiita.com/quoth/items/b9542e8f4892d419bdfd

alias名は brt -> branch remote time, blt -> branch local time のつもり

自分のところでは問題なく動くが、.gitconfig内のダブルクォートが少し気になる。
shellの種類や設定によっては動かないかも。

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
2