Reputation: 52449
I just want to get a quick glance at the history of a project by having git log
show only the commit date, nothing else. How can we best do that?
It turns out I was actually asking for the author date, which is what is shown by git log
. To see the committer date too, which can be different, run git log --pretty=fuller
.
See also here: Why is git AuthorDate different from CommitDate?
To help make this point that there are different dates: to set an author date when running git commit
, use:
git commit ---date "<date>"
To set also the committer date, you'd have to do:
GIT_COMMITTER_DATE="<date>" git commit --date "<date>"
See here: How can one change the timestamp of an old commit in Git?
Upvotes: 0
Views: 2690
Reputation: 52449
(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.
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
$(git rev-list --max-parents=0 HEAD)
gets the commit hash of the first commit.
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.
-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.
-1
in git log
means: "just 1 commit"HEAD
is the currently-checked-out commit hashUpvotes: 1
Reputation: 28869
If you want to see only the committer date (the date the commit was written with it's current ID):
git log --format=%cd
If you want to see only the author date (the date the commit was originally written, but may differ from the committer date if the commit was amended, rebased, cherry-picked, etc, which caused it to get a new commit ID):
git log --format=%ad
More info on the difference between committer and author dates: Why git AuthorDate is different from CommitDate?.
Dates can be displayed in different ways. Here's a list of built-in options.
Also, if you don't want to use a pager, just add --no-pager
after the git
command, like this:
git --no-pager log --format=%ad
Upvotes: 3