1. The easy way:
(This answer was the first answer; this part was added after @TTT wrote the comment below which taught me this easier way).
# ad = author date
git log --format=%ad
# cd = committer date
git log --format=%cd
%cd
stands for "Committer Date", apparently. Contrast that with %ad
, which stands for "Author Date". (I'm not sure what the differences are nor how or why these dates would differ).
Thank you, @TTT. Now that I see how that works, I found the appropriate format string sections in the documentation:
Do man git log
, then search for the regular expression format:<format-string>
by pressing / and typing that in and pressing Enter. Searching for %cd
also jumps down to that section.
2. The hard way (my initial attempt):
Tested on Linux Ubuntu:
One way to get the author date (--format=%ad
, above, as I now know after-the-fact) is to filter the output of git log
through grep
. Here is the answer for git log HEAD
. Replace HEAD
with any branch name or commit hash you want.
See just the dates for all commits:
git log HEAD | grep 'Date:' | grep -o ' .*$' | grep -o '[^\r\n\t\f\v ].*$'
Sample output:
Sun Apr 26 19:17:49 2020 -0700
Sun Apr 26 16:51:21 2020 -0700
Sun Apr 26 15:35:16 2020 -0700
Sat Apr 25 23:21:37 2020 -0700
Sat Apr 25 23:12:07 2020 -0700
Sat Apr 25 23:06:44 2020 -0700
Tue Apr 14 23:02:34 2020 -0700
Sun Apr 5 23:26:20 2020 -0700
Sun Apr 5 23:20:34 2020 -0700
Sun Apr 5 18:08:44 2020 -0700
Sun Apr 5 17:56:08 2020 -0700
Sun Apr 5 10:06:04 2020 -0700
Sat Apr 4 20:58:33 2020 -0700
Sat Mar 21 14:38:53 2020 -0700
Thu Mar 19 20:37:27 2020 -0700
Thu Mar 19 18:16:55 2020 -0700
Thu Mar 19 18:01:53 2020 -0700
Or, to just see the most-recent date only, add -1
:
git log -1 HEAD | grep 'Date:' | grep -o ' .*$' | grep -o '[^\r\n\t\f\v ].*$'
Output:
Sun Apr 26 19:17:49 2020 -0700
...or to see just the oldest date, use $(git rev-list --max-parents=0 HEAD)
instead of HEAD
(again, replace HEAD
in that command with the appropriate branch or commit you'd like to view):
git log -1 $(git rev-list --max-parents=0 HEAD) | grep 'Date:' \
| grep -o ' .*$' | grep -o '[^\r\n\t\f\v ].*$'
Output:
Thu Mar 19 18:01:53 2020 -0700
Explanation
$(git rev-list --max-parents=0 HEAD)
gets the commit hash of the first commit.
- See my answer here: How to show first commit by 'git log'?
grep 'Date:'
finds only lines with the text Date:
in them.
grep -o ' .*$'
strips off the Date:
part by matching only the 3 spaces and the text following that.
- For the
-o
part, see: Can grep show only words that match search pattern?
grep -o '[^\r\n\t\f\v ].*$'
strips off the preceding spaces by matching only non-whitespace chars.
- See my answer here: Unix & Linux: Any non-whitespace regular expression
-1
in git log
means: "just 1 commit"
HEAD
is the currently-checked-out commit hash