Skip to content
Tutorials Center
My learning

Topics

Git Reference ยท Revisions and Pathspecs

Date formats in Git

Reference for dates in Git: accepted input forms (ISO 8601, RFC 2822, raw, relative), --date output formats, GIT_AUTHOR_DATE and --since expressions.

Git handles dates in two directions. Input: you give a date to --date, GIT_AUTHOR_DATE, GIT_COMMITTER_DATE, --since, --until or @{2.days.ago}. Output: you pick how git log, git show and git blame print dates with --date=<format> or the log.date setting. Internally every commit stores a Unix timestamp plus a time zone offset, such as 1700000000 +0100.

For input, Git has a forgiving parser called approxidate. It accepts strict forms (raw, ISO 8601, RFC 2822) and informal phrases such as yesterday, 3 weeks ago or last friday. Strict forms are the safe choice for scripts, because informal phrases depend on the current time and give different results from one day to the next.

Terminal
GIT_AUTHOR_DATE="2024-03-05T10:00:00+0000" git commit -m "x"
git log --since="2 weeks ago" --date=short
git log --date=format:'%Y-%m-%d %H:%M' --format='%ad %s'

Try it

Bash Fixed dates and output formats

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Input forms accepted for commit dates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Input formats

Form Example Notes
Git internal (raw) 1709649000 +0200 Unix seconds and a zone offset. Add @ in some contexts: @1709649000.
ISO 8601 2024-03-05T14:30:00+0100, 2024-03-05 14:30:00Z Best for scripts; the zone is respected.
RFC 2822 Tue, 5 Mar 2024 14:30:00 +0100 The format used in email headers and patches.
Dotted / numeric 2024.03.05, 03/05/2024, 5.3.2024 Month and day order follows the format shape; ambiguous numbers are guessed.
Relative (approxidate) yesterday, 2.days.ago, last tuesday, noon yesterday Used mostly with --since, --until, @{...}.

Output formats (--date=): default, local, iso (iso8601), iso-strict, rfc (rfc2822), short (date only), relative, human, raw, unix, and format:<strftime> or format-local:<strftime>. Modifiers -local (as in iso-local) convert to your current zone.

Errors and edge cases: an invalid date makes a commit fail with fatal: invalid date format. When no zone is given, the local zone of the machine is used, so equal text can mean different instants on different computers. --since with a vague phrase is evaluated relative to now, and git log --since=yesterday may not match when you run it twice a day apart.

Usage notes

  • Reproducible commits. Set both GIT_AUTHOR_DATE and GIT_COMMITTER_DATE (and the names) to get the same commit hash every time, which is why the examples on this site use fixed values.
  • --date on commit sets only the author date. The committer date still comes from GIT_COMMITTER_DATE or the clock. git commit --amend --reset-author refreshes the author date to now.
  • relative and human change with the clock. Avoid them in anything you compare or store. Use iso-strict or raw for machine-readable output.
  • Time zones are part of the date. iso shows the author's zone as written in the commit; local converts it to yours. Two commits made at the same instant in different zones print different text.
  • Set a default with log.date (see log.*); command-line --date overrides it.
  • Format placeholders: in --format, %ad honors --date, while %aD (RFC 2822), %ai (ISO-like), %aI (strict ISO), %as (short), %at (Unix) and %ar (relative) are fixed styles; see git log --pretty.
  • Reflog selectors such as main@{yesterday} or HEAD@{2.weeks.ago} use the same parser, but read your local reflog, not the commit dates; see @{n} and @{date}.
  • Year-less input like Mar 5 assumes the current year, and times in the future may be moved back into the past; add the year in scripts.