A simple fix is to pass the --pretty=oneline parameter, which makes it all fit on a single line. It's taking up less space, but missing crucial information like the date of the commit. There are longer versions of that same --pretty parameter. In fact, it allows you to specify all the fields you want in the output.
For all commits where you want to change the date, replace pick by edit (or just e ), then save and quit your editor. The first date is the commit date, the second one is the author date. Repeat the process until you amend all your commits.
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.
The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order; that is, the most recent commits show up first.
In addition to --date=(relative|local|default|iso|iso-strict|rfc|short|raw)
, as others have mentioned, you can also use a custom log date format with
--date=format:'%Y-%m-%d %H:%M:%S'
This outputs something like 2016-01-13 11:32:13
.
NOTE: If you take a look at the commit linked to below, I believe you'll need at least Git v2.6.0-rc0 for this to work.
In a full command it would be something like:
git config --global alias.lg "log --graph --decorate
-30 --all --date-order --date=format:'%Y-%m-%d %H:%M:%S'
--pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'"
I haven't been able to find this in documentation anywhere (if someone knows where to find it, please comment) so I originally found the placeholders by trial and error.
In my search for documentation on this I found a commit to Git itself that indicates the format is fed directly to strftime
. Looking up strftime
(here or here) the placeholders I found match the placeholders listed.
The placeholders include:
%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%c Date and time representation appropriate for locale
%d Day of month as decimal number (01 – 31)
%H Hour in 24-hour format (00 – 23)
%I Hour in 12-hour format (01 – 12)
%j Day of year as decimal number (001 – 366)
%m Month as decimal number (01 – 12)
%M Minute as decimal number (00 – 59)
%p Current locale's A.M./P.M. indicator for 12-hour clock
%S Second as decimal number (00 – 59)
%U Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w Weekday as decimal number (0 – 6; Sunday is 0)
%W Week of year as decimal number, with Monday as first day of week (00 – 53)
%x Date representation for current locale
%X Time representation for current locale
%y Year without century, as decimal number (00 – 99)
%Y Year with century, as decimal number
%z, %Z Either the time-zone name or time zone abbreviation, depending on registry settings
%% Percent sign
In a full command it would be something like
git config --global alias.lg "log --graph --decorate -30 --all --date-order --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'"
The others are (from git help log
):
--date=(relative|local|default|iso|rfc|short|raw)
Only takes effect for dates shown in human-readable format,
such as when using "--pretty". log.date config variable
sets a default value for log command’s --date option.
--date=relative shows dates relative to the current time, e.g. "2 hours ago".
--date=local shows timestamps in user’s local timezone.
--date=iso (or --date=iso8601) shows timestamps in ISO 8601 format.
--date=rfc (or --date=rfc2822) shows timestamps in RFC 2822 format,
often found in E-mail messages.
--date=short shows only date but not time, in YYYY-MM-DD format.
--date=raw shows the date in the internal raw git format %s %z format.
--date=default shows timestamps in the original timezone
(either committer’s or author’s).
There is no built-in way that I know of to create a custom format, but you can do some shell magic.
timestamp=`git log -n1 --format="%at"`
my_date=`perl -e "print scalar localtime ($timestamp)"`
git log -n1 --pretty=format:"Blah-blah $my_date"
The first step here gets you a millisecond timestamp. You can change the second line to format that timestamp however you want. This example gives you something similar to --date=local
, with a padded day.
And if you want permanent effect without typing this every time, try
git config log.date iso
Or, for effect on all your git usage with this account
git config --global log.date iso
After a long time looking for a way to get git log
output the date in the format YYYY-MM-DD
in a way that would work in less
, I came up with the following format:
%ad%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08
along with the switch --date=iso
.
This will print the date in ISO format (a long one), and then print 14 times the backspace character (0x08), which, in my terminal, effectively removes everything after the YYYY-MM-DD part. For example:
git log --date=iso --pretty=format:'%ad%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%aN %s'
This gives something like:
2013-05-24 bruno This is the message of the latest commit.
2013-05-22 bruno This is an older commit.
...
What I did was create an alias named l
with some tweaks on the format above. It shows the commit graph to the left, then the commit's hash, followed by the date, the shortnames, the refnames and the subject. The alias is as follows (in ~/.gitconfig):
[alias]
l = log --date-order --date=iso --graph --full-history --all --pretty=format:'%x08%x09%C(red)%h %C(cyan)%ad%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08 %C(bold blue)%aN%C(reset)%C(bold yellow)%d %C(reset)%s'
I needed the same thing and found the following working for me:
git log -n1 --pretty='format:%cd' --date=format:'%Y-%m-%d %H:%M:%S'
The --date=format
formats the date output where the --pretty
tells what to print.
You can use the field truncation option to avoid quite so many %x08
characters. For example:
git log --pretty='format:%h %s%n\t%<(12,trunc)%ci%x08%x08, %an <%ae>'
is equivalent to:
git log --pretty='format:%h %s%n\t%ci%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08%x08, %an <%ae>'
And quite a bit easier on the eyes.
Better still, for this particular example, using %cd
will honor the --date=<format>
, so if you want YYYY-MM-DD
, you can do this and avoid %<
and %x08
entirely:
git log --date=short --pretty='format:%h %s%n\t%cd, %an <%ae>'
I just noticed this was a bit circular with respect to the original post but I'll leave it in case others arrived here with the same search parameters I did.
Be aware of the "date=iso
" format: it isn't exactly ISO 8601.
See commit "466fb67" from Beat Bolli (bbolli
), for Git 2.2.0 (November 2014)
Git's "ISO" date format does not really conform to the ISO 8601 standard due to small differences, and it cannot be parsed by ISO 8601-only parsers, e.g. those of XML toolchains.
The output from "
--date=iso
" deviates from ISO 8601 in these ways:
- a space instead of the
T
date/time delimiter- a space between time and time zone
- no colon between hours and minutes of the time zone
Add a strict ISO 8601 date format for displaying committer and author dates.
Use the '%aI
' and '%cI
' format specifiers and add '--date=iso-strict
' or '--date=iso8601-strict
' date format names.
See this thread for discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With