As the title says: I'd like all commits I push to GitHub to appear with the timestamp of the push rather than of the commit, in the GitHub's commits tab.
I use quite a standard workflow:
<do some work>
git add -u
git commit -m "Message 1."
...
<do some work>
git add -u
git commit -m "Message N."
git push myrepo master
This makes all N commits show in GitHub, which is fine and good. But the time of the commits is shown as well, which I don't like. I would much more prefer to show only the timestamp of the last of them (or of the push).
GitHub push time
The time at which you push is forever viewable on the GitHub API. If you want to hide that, there is no alternative: use a cron job.
Commit data time
The commit time on the commit data can be controlled with the environment variables:
For
--amend
, there use the--date
option for the author date: How can one change the timestamp of an old commit in Git?There are no further time indications on the commit message object, so that is enough for privacy.
You might want to do this automatically from
post-commit
hook as explained at: Can GIT_COMMITTER_DATE be customized inside a git hook?Here is a more advanced hook that makes your commits will start at midnight every day, and increment by one second for every new commit. This keeps commits sorted by time, while still hiding the commit time.
.git/hooks/post-commit
GitHub upstream.
Don't forget to:
Tested on git 2.19, Ubuntu 18.04.
Don't forget to also handle:
git rebase
with apost-rewrite
hook: git rebase without changing commit timestampsgit am
with--committer-date-is-author-date
as explained at Can GIT_COMMITTER_DATE be customized inside a git hook?or else the committer date still leaks.
Bulk history modification
Here is a way to fix the commit times for all commits in an existing range to midnight while keeping the date unchanged:
See also: How can one change the timestamp of an old commit in Git?
You have several options: