Thursday, January 24, 2019

Git commit with specific date

Very interesting Git option I just found: --date. When making a commit, you can specify the date manually. However, if you make a new commit with a past date, it will still be shown as the last commit, even with a date prior to the previous commit.

A new commit at January 1, 2019, 12:00, specifying timezone UTC-2:

git commit -m "Comment" --date="2019-01-01T12:00:00-02:00"

Changing the date of the last commit, using UTC+0 as timezone. Will be prompted to write the comment:

git commit --amend --date="2019-01-01T12:00:00Z"

This goes hand-in-hand with this current date trick.

No comments: