G
G
gera72021-11-16 10:09:04
git
gera7, 2021-11-16 10:09:04

How to change the time when the commit was pushed to the repository, is it possible?

The repository has a commit that was pushed 2 hours ago at 8:00 (commited 2 hours ago). Can I somehow change this time, for example, to yesterday at 22:00, what would be displayed to me committed 12 hours ago?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-11-16
@gera7

Each commit stores two times: Author date and Commiter date.
doc on GitHub .
To see both times, you can set the git log command with the --format=fuller flag.

$ git log --format=fuller -1
commit f0eac...
Author:     ... <...>
AuthorDate: Tue Nov 16 09:00:00 2021 +0300
Commit:     ... <...>
CommitDate: Mon Nov 15 22:00:00 2021 +0300
...

The flag --datechanges the Author date, which shows the git log, while GitHub shows the Committer date. To change it, you have to act a little more difficult. You need to define an environment variable GIT_COMMITTER_DATE. For example, in bash it is done like this:
GIT_COMMITTER_DATE=$(date -R -d 'yesterday 22:00') git commit --amend --no-edit --date='yesterday 22:00'

I don't know how to do this in Windows, but I'm sure you can.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question