LoginSignup
3
1

More than 3 years have passed since last update.

gitで時間の表示フォーマットを変更する

Last updated at Posted at 2019-08-28

TR;DR

git log --date=<format>
git show --date=<format>
git branch --format='%(authordate:<format>)'

<format>部分を調べた際に、探すのに時間かかってしまったのでメモ

ドキュメント

git branchのドキュメントの--format見ると、git-for-each-refと同じって書いてある

--format
A string that interpolates %(fieldname) from a branch ref being shown and the object it points at. The format is the same as that of git-for-each-ref[1].

git-for-each-refのドキュメント見ると、日付の形式はgit-rev-listを見てねって書いてある

As a special case for the date-type fields, you may specify a format for the date by adding : followed by date format name (see the values the --date option to git-rev-list[1] takes).

git rev-listのドキュメントにやっと書いてあった

ただし、独自の形式にする場合は
--date=format:...はシステムのstrftimeに送るからパラメータはそっち見てねってあるので

strftime を見ないといけない

サンプル書式

$ git branch --format='%(authordate)'
Tue Aug 27 19:34:50 2019 +0900

$ git branch --format='%(authordate:relative)'
16 hours ago

$ git branch --format='%(authordate:local)'
Tue Aug 27 19:34:50 2019

$ git branch --format='%(authordate:iso)'
2019-08-27 19:34:50 +0900

$ git branch --format='%(authordate:iso-strict)'
2019-08-27T19:34:50+09:00

$ git branch --format='%(authordate:rfc)'
Tue, 27 Aug 2019 19:34:50 +0900

$ git branch --format='%(authordate:rfc2822)'
Tue, 27 Aug 2019 19:34:50 +0900

$ git branch --format='%(authordate:short)'
2019-08-27

$ git branch --format='%(authordate:raw)'
1566902090 +0900

$ git branch --format='%(authordate:unix)'
1566902090

$ git branch --format='%(authordate:default)'
Tue Aug 27 19:34:50 2019 +0900

独自フォーマット

$ git branch --format='%(authordate:format-local:%Y-%m-%d %H:%M:%S)'
2019-08-27 19:34:50

:humanは使えなかった

$ git --version
git version 2.17.1

$ git branch --format='%(authordate:human)'
fatal: unknown date format human

恐らくバージョンによるもので、version 2.21.0 から追加された模様です。
--date=humanについての表記がver 2.20.0にはなく、ver 2.21.0 からはありました。

3
1
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
3
1