DEV Community

Cover image for Is it possible to create a commit with a different date?
AbdlrahmanSaber
AbdlrahmanSaber

Posted on

Is it possible to create a commit with a different date?

This a first short tutorial from a Git Tricks series.

Sometimes, you might run into a situation where you need to create a commit with a different date than the current one. Luckily, you can handle this using following timestamp in git

  • GIT_AUTHOR_DATE
  • GIT_COMMITTER_DATE

you might be now you're wondering what's actually the difference between Author and Committer

Let's Understanding dates in Git: author date vs. committer date & ‘approxidate

 

The author is the person who originally wrote the work, whereas the committer is the person who last applied the work.

 

So if, for instance, you send in a patch to a project, the author date will be when you made the original commit but the committer date will be when the patch was applied. Another common scenario is rebasing: rebasing will alter the commit date, but not the author date.

The Command


GIT_AUTHOR_DATE='Mon May 18 19:32:11 2022 -0400' \
  GIT_COMMITTER_DATE='Mon May 18 19:32:11 2022 -0400'\
  git commit -m 'Commit from the past'

Enter fullscreen mode Exit fullscreen mode

As shown in the example above, you can set both values to any date you like and your code will be committed on that date.

Note
you can also use other formats

Date formats

RFC 2822 Mon, 18 May 2022 19:32:11 -0400
ISO 8601 2022-05-18 19:32:11 -0400
local Mon May 18 19:32:11 2022
short 2022-05-18
relative 5.seconds.ago, 2.years.3.months.ago, 6am yesterday

Let’s connect on LinkedIn, Twitter

Top comments (0)