So you want to add some changes to code, and make it as if your last commit has the changes. Also, you want to keep the date of your last commit. Easy!
- Do some changes.
- Make a temporary commit.
- Rebase interactive, squash last commit.
- Commit and amend. Set dates by exposing 2 ENV variables
GIT_AUTHOR_DATE
andGIT_COMMITTER_DATE
.
So, it would look something like this, when doing via CLI:
git add .
git commit -m "update"
git rebase -i HEAD~2
GIT_AUTHOR_DATE="1641042000 +0600" GIT_COMMITTER_DATE="1641042000 +0600" git commit --amend
git push --force origin {BRANCH_NAME}
NOTE: Above, 1641042000
is a date represented by a unix timestamp, and +0600
is a time zone offset.
NOTE: Above, replace {BRANCH_NAME}
with your active branch name (for example master
).
You can also do:
git reset --soft HEAD~1
This will get you back to the state you were in, before doing your last commit. You can do more changes, followed with:
GIT_AUTHOR_DATE="1641042000 +0600" GIT_COMMITTER_DATE="1641042000 +0600" git commit -m "some commit message"