Note
|
This could be use to set any date to a commit (not only in the past) |
Warning
|
Using a date in the future could have unkown side effect on Github, Gitlab, … |
When dealing with a commit, git features both an author and a committer in order to keep trace of who wrote the code. Each of them have a name, an email and a date for each commit.
The authored date tracks when the code has been written while the comitted date tacks when it has been merged. In particular, when pushing a commit to a remote repository, the committed date is overwritten.
Everything can be overwritten using following environment variables:
GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL
GIT_AUTHOR_DATE
GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL
GIT_COMMITTER_DATE
(see https://git-scm.com/docs/git-commit#_commit_information for more details)
It is also possible to overwrite the author date as follow while doing a commit:
git commit --date "<YYYY>-<MM>-<DD>T<hh>:<mm>:<ss>Z"
(see https://git-scm.com/docs/git-commit#_date_formats for more details about date format)
It can be done recursively from a specific commit <XYZ> (excluded) as follow:
git rebase -r <XYZ> --exec 'git commit --amend --no-edit --date="<YYYY>-<MM>-<DD>T<hh>:<mm>:<ss>Z"
Using prezto aliases:
gc --date "<YYYY>-<MM>-<DD>T<hh>:<mm>:<ss>Z"