Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure 'git log' to show 'commit date'

Tags:

git

git-log

How can I configure git log to show commit date instead of author date?

like image 893
michael Avatar asked Oct 22 '22 10:10

michael


People also ask

What is the date in git log?

When you run git log , by default you will see the author date. If you want to see commit date, you can use one of the many command line options, such as --pretty=fuller . Note the (slight) difference between the author date and commit date above. The author date is my original, unedited, commit time.

Can you see the time of a git commit?

Hover over the 'xx days ago' label on the right-hand side, pause and wait for the Tooltip to appear. Hover over the 'xx days ago' label next to the relevant commit under the History tab, pause and wait for the Tooltip to appear.

How do I display a commit?

The HEAD reference always points to the last commit of the current branch. Therefore, you can use git-show to display the log message and diff output of the latest commit.


2 Answers

There are several options to pretty print the date. Probably the easiest is to just use one of the pre-baked --pretty formats, like git log --pretty=fuller - this will show both dates. If you want to see only one date, but make it the commit date, you can use git log --format=<some stuff>. All the allowable codes for defining the format are documented in git help log. The commit date is one of %cd, %cD, %cr, %ct or %ci, depending on what format you prefer it in.

If it's something you want to do often, put it in an alias or write an auxiliary script to save on typing.

like image 202
twalberg Avatar answered Oct 23 '22 22:10

twalberg


You can use --pretty=format and use %cr for commit date relative.

For example:

$ git log --graph --pretty=format:'%C(auto)%h%d (%cr) %cn <%ce> %s'

You can define an alias in git to make this easier to use. I have the following in my .gitconfig:

[alias]
# see `git help log` for detailed help.
#   %h: abbreviated commit hash
#   %d: ref names, like the --decorate option of git-log(1)
#   %cn: commiter name
#   %ce: committer email
#   %cr: committer date, relative
#   %ci: committer date, ISO 8601-like format
#   %an: author name
#   %ae: author email
#   %ar: author date, relative
#   %ai: author date, ISO 8601-like format
#   %s: subject
# my awesome git log replacement
lol  = log --graph --pretty=format:\"%C(auto)%h%d%Creset %C(cyan)(%cr)%Creset %C(green)%cn <%ce>%Creset %s\"
# same as above, but ISO date
lold = log --graph --pretty=format:\"%C(auto)%h%d%Creset %C(cyan)(%ci)%Creset %C(green)%cn <%ce>%Creset %s\"
# using build-in standards
lol2 = log --oneline --graph --decorate
# shows branches and their last commits
lol3 = log --all --graph --decorate --oneline --simplify-by-decoration

On Linux or similar systems, you can use single-quotes ' instead of double-quotes ":

[alias]
lol = log --graph --pretty=format:'%C(auto)%h%d%Creset %C(cyan)(%cr)%Creset %C(green)%cn <%ce>%Creset %s'

With this, simply run git lol, or the other variants to see the pretty output.

Here's the output of git lol --simplify-by-decoration:

git lol output

  • It looks good. :)
  • lol is easier to type than log, and sounds better too.
    • Also gives you access to the regular git log if you ever need it.
  • Your eyes can scan contents quickly by the different colors.
  • Names and e-mails are very useful for large projects/org with many contributors.
  • Using default coloring for hash/ref as it is already pretty good.

Here's the output of git lold with dates in ISO format. Useful to see the exact date/time a commit is made, with the bonus of being able to see the contributor's timezone easily.

enter image description here

Edit 2020-06: Added screenshots. Updated to use %C(auto) (auto/default coloring) for %h (commit hash) and %d (ref names). Added %cn (commiter name) in addition to email.

like image 101
raychi Avatar answered Oct 23 '22 23:10

raychi