-
-
Save lisachacho/f23f5894c5db27c4eafbf9c22f36d788 to your computer and use it in GitHub Desktop.
β³Yes β Can you reset the commits?
β³Yes β Reset and start the stage/commit process over with custom dating
β³No β Push and then backdate them
β³No β Set a custom date for your commit
When you're done, check the cleanup section.
I haven't tested this with IDEs so I recommend using Git in the terminal, the old fashioned way. Do this all in the same terminal window!
git stage .
The .
refers to the root folder, i.e. everything
Then, set your custom date by exporting two environment variables:
export GIT_AUTHOR_DATE="Fri May 2 08:23:39 2025 -0400" GIT_COMMITTER_DATE="Fri May 2 08:23:39 2025 -0400"
Now, commit your changes (with a commit message):
git commit -m "commit message"
Finally, clear your environment variables:
unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE
Remember to always unset the environment variables!!
Caution
1οΈβ£ Be sure you have the ability to force push to your repo/branch!
2οΈβ£ If you have any Github Actions, CI/CD, or any kind of checks attached to your repo, this will not trigger those checks.
3οΈβ£ Finally, if you do not unset
the env variables which overwrite the commit date between each commit in the rebase (and after this is done), it will set every single commit to the same time. Be sure to unset
!
First, take a look at your commits in order to decide which ones you want to modify:
git log
Grab the SHA from the commit before the earliest commit you'd like to change.
Let's start an interactive rebase (don't be scared):
git rebase -i <YOUR_SHA_HERE>
Running this command gives you a list of commits (in opposite order than you're used to) that looks something like this:
pick f7f3f6d initially creating the HTML file "Hello.html"
pick 310154e adding some code to "Hello.html"
pick a5f4a0d final cleanup
# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified). Use -c <commit> to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Warning
Now you're in VIM.
Use the following command to edit the output:
i
And using your keyboard arrows, navigate to each of the commits which you'd like to edit.
Change each of those commits from pick
to edit
. For example:
pick f7f3f6d initially creating the HTML file Hello.html
pick 310154e adding some code to Hello.html
pick a5f4a0d final cleanup
# this will become...
edit f7f3f6d initially creating the HTML file Hello.html
edit 310154e adding some code to Hello.html
pick a5f4a0d final cleanup
Now, exit Insert
mode in VIM by pressing ESCAPE
on your keyboard.
Type the following and hit enter to finalize your changes:
:x
Git will begin the rebase and skip all the commits which you left as pick
but stop on the commits that are labeled edit
.
Note
This process will be repeated with every commit for which you picked edit
.
Git rewinds you back to the last edit
commit in that list and drops you on the command line with the following message:
Stopped at f7f3f6d... initially creating the HTML file Hello.html
You can amend the commit now, with
git commit --amend
Once you're satisfied with your changes, run
git rebase --continue
Now that you're rewound to that commit, you can make changes!
We want to change two environment variables: GIT_AUTHOR_DATE
and GIT_COMMITTER_DATE
. These should have the same value.
export GIT_AUTHOR_DATE="Fri May 2 14:23:39 2025 -0400"
export GIT_COMMITTER_DATE="Fri May 2 14:23:39 2025 -0400"
Then, re-commit this change with the ammend flag:
git commit --amend
This will open VIM again. You can make changes to your commit message (i
> Edit text > ESCAPE > :x
) or just continue:
:x
Finally, unset the env variables and continue the rebase:
unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE
git rebase --continue
... and repeat.
Ya gotta use force (don't be scared):
git push --force
Remember to always unset the environment variables!!