6

Let's say I do this command: git log -4 --pretty=format:%h

How do I add date/time to each result?

Andrew Paul Simmons
  • 4,334
  • 3
  • 31
  • 39
  • With Git 2.25 (Q1 2020), you also have [`git show -s --pretty=reference `](https://stackoverflow.com/a/59380120/6309) which can be of interest. – VonC Dec 17 '19 at 18:32

1 Answers1

13

For Committer Date use %cd:

git log -4 --pretty=format:"%h - %cd"

-

For Author Date use %ad:

git log -4 --pretty=format:"%h - %ad"

-

For more options refer this.

Domain
  • 11,562
  • 3
  • 23
  • 44
  • only problem, those dates are verbose, like `Fri Jul 22 16:51:46 2022 +0200`. `%cr` gives a relative date, and `%cs` gives a short date, but I haven't figured out how to have a short time, like `16:51` instead of `16:51:46 2022 +0200`... – Kai Carver Jul 25 '22 at 07:39
  • this documents the `--pretty` formats https://git-scm.com/docs/pretty-formats – Kai Carver Jul 25 '22 at 08:49
  • `%cI` is ok as mentioned here https://stackoverflow.com/a/28255959/153144 This works ok in my time zone: `git log --pretty=format:'%cI %h %s %an' -n 20 | sed 's/:[0-9][0-9]+02:00//'` – Kai Carver Jul 25 '22 at 08:57