LoginSignup
0
0

More than 3 years have passed since last update.

gitのfor-each-refで各ブランチで最後にcommitした人とその更新時刻を一覧表示させる。

Last updated at Posted at 2019-09-12

普段はあまりそんな状況ないんですがふと今の作業ブランチだけでなくて、すべてのブランチを対象に最新のcommit情報をその更新時刻付きで表示したくなり「うーん、うまいやり方ないかなー」と思ってググったらgit for-each-refが使えるとのこと。知らなかった。

公式ドキュメント

Git - git-for-each-ref Documentation - Git SCM

【例】

git for-each-ref \
--sort=-committerdate \
--count=10 \
--format="
Date: %(color:red)%(authordate:iso)%(color:reset)
%(color:green)[%(authorname)]%(color:reset)
Ref: %(color:yellow)%(refname:short)%(color:reset)
Subject: %(subject)" \
refs/heads refs/remotes

上の例だと

  • 最新のコミット順
  • 10件
  • 日付とブランチ名とユーザ名とcommitメッセージ含め

て表示してくれる。
(色とかつけてるからごちゃごちゃしてるけど、整理すればシンプル。)

for-each-refは単体で使うよりこれを使ってブランチ一覧を取得してその上で何かする、みたいな状況で利用されることが多いらしい。

とはいえ、上の例を参考に上手く使えば

「さっき作業してたブランチなんだっけ?」

とか

「あのブランチって誰がいつ切ったの?」

みたいな調査が楽にできそう。

長いので.gitconfigにaliasを追加しておけば良さそう。

[alias]
    history = for-each-ref --sort=-committerdate --count=10 --format='Date: %(color:red)%(authordate:iso)%(color:reset)\t%(color:green)[%(authorname)]%(color:reset)\nRef: %(color:yellow)%(refname:short)%(color:reset)\nSubject: %(subject)\n' refs/heads refs/remotes

20180504172346.png

RedashのRepo.で試しにやってみた図)


...と思ったらすでにこういうのがあるらしい。
まあ、誰かしら作ってるとは思ったけど。


参考

ブランチ一覧を更新時刻つきで表示したい場合、gitのfor-each-refが使える。 - Bye Bye Moore

ブランチを最新コミット順に並べたら幸せになれた - kakakakakku blog


この記事は著者のブログからの転載記事となります。

gitのfor-each-refで各ブランチで最後にcommitした人とその更新時刻を一覧表示させる。 - DOT NOTES

0
0
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
0
0