Committime
Altering git commit times is generally a poor idea and is certainly not a best practice. The ideas herein help understand the internals of git; please do not use them for any serious matter.
Note: This tool will not work with cryptographically signed commits. See this stackoverflow answer for a brief overview of why signing commits is important.
What
Git's best and worst features involve changing history. Anyone can change commit history. It's good to be aware of git's internals.
Each commit has an associated author date and committer date.
A regular git log
only shows the author date.
To see both a commit's author date and committer date:
git log --pretty=fuller
resulting in something like
commit 293a1b884253f9efbc77b2d19d312b28874f523c
Author: Jack Fletcher <jdfletch97@gmail.com>
AuthorDate: Thu Aug 22 14:45:46 2019 -0500
Commit: Jack Fletcher <jdfletch97@gmail.com>
CommitDate: Thu Aug 22 14:45:46 2019 -0500
Add real blog posts
Git allows these dates to be changed by rewriting history.
Do not use this on public commits (i.e., ones that have already been pushed to a repository) unless you're working solo and have the --force
.
Why
Changing an unsigned git commit's author date or committer date may be seen as a bit questionable. That's because it is. As stated earlier, I would not recommend using these techniques for any serious matter.
How
To change the author date of last commit:
git commit --amend --no-edit --date "$date"
To change the committer date of last commit:
GIT_COMMITTER_DATE="$date" git commit --amend --no-edit
These methods can be combined with a git rebase -i
and marking the commit to change with edit
to change an arbitrary commit:
git rebase -i HEAD~3
# change pick to edit in rebase screen
# insert above command to change date
git rebase --continue
Checkout the git book for more git rebase
information.
CLI
I created committime
just to see what is possible for a low-effort program:
committime
shows the user a list of latest commits.
Once a commit is selected, committime
shows the possible formats of date entry.
Additionally, the user can conveniently specify that the author date and committer date should match.
After entering the date(s) for the commit, committime
does the heavy lifting.
Behind the scenes, committime
is running a git filter-branch
operation to change the environment variables GIT_AUTHOR_DATE
and GIT_COMMITTER_DATE
for the chosen commit.
git filter-branch
information can be found in the git docs or book.
Open source code
committime
is a hobby project and free to use, modify, and even sell within the bounds of the liberal MIT license.
You'll find the most recent version at https://github.com/jackfletch/committime.