1

How can I set up date formatting in git log output so that dates appear in different formats?

hist = log --all --graph\n--pretty=format:'%Cred%h%Creset %ad -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\n--abbrev-commit --date=relative

I want first date to be --date=local and last date --date=relative. Is it possible?

Nik
  • 9,063
  • 7
  • 66
  • 81
  • A possibility is to use `-n` and specify different date formats. – devnull Jul 16 '13 at 05:30
  • Possible duplicate of [Git Log Date Formats](http://stackoverflow.com/questions/7853332/git-log-date-formats). –  Jul 16 '13 at 05:44
  • Not duplicate, because my question was "how I can use two formates in same time" and %ad %cr is the answer :-) – Nik Jul 16 '13 at 08:19

1 Answers1

4

Update

So I was wrong, --format can be used with the --abbrev-commit and --date=relative flags, so the problem was strictly the existence of \n in your command. The flags are still unnecessary, however, because their place holders are already in your command, as I've explained below.


It appears that the --format option is not compatible with the --abbrev-commit and --date=relative options. If you remove them, you'll get what you want. You also have \n in your command that's not a part of the format, nor are they a legal arguments to the command, so those should be removed too:

hist = log --all --graph --pretty=format:'%Cred%h%Creset %ad -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

In addition, the --abbrev-commit and --date=relative flags are unnecessary, since %h already gives you abbreviated-commits, %ad automatically defaults to the user's local time (if they haven't set their log.date config variable), and %cr displays the date in relative time (e.g. "7 days ago").

From the official Kernel Git documentation for git log:

Commit Formatting

log.date config variable sets a default value for log command’s --date option.

--date=default shows timestamps in the original timezone (either committer’s or author’s).

Pretty Formats

  • %h: abbreviated commit hash
  • %ad: author date (format respects --date= option)
  • %cr: committer date, relative
Community
  • 1
  • 1
  • Thats brilliant! :-) Just one question — how can I add custom format for first date? For example I want it to be like `01.01.13 12:08`. Upd: see your edit, going to use --date option – Nik Jul 16 '13 at 05:40
  • According to [dmedvinsky's answer](http://stackoverflow.com/questions/7853332/git-log-date-formats/7853670#7853670), there is no way to do a custom date format yet. I also searched through the `git log` and `config` documentation, and I didn't see anything to that effect. –  Jul 16 '13 at 05:46
  • Unfortunately seems to be true – Nik Jul 16 '13 at 05:48
  • I see you stated "problem" after update, but it has nothing to do with my original question, if I use %ad and %cr even with \n, it works fine. And `\n--abbrev-commit --date=relative` works fine too. My question was "how I can use two formates in same time" and `%ad %cr` is the answer :-) – Nik Jul 16 '13 at 08:17