Sublime Forum

Edit commit without changing the date

#1

Is there any way I can edit a commit from a few days ago (adding an extra line of code) without changing the date of the commit?

0 Likes

#2

I think this is not possible with git in general, as its philosophy doesn’t allow to change commits but only to create new ones replacing the other.

Edit: Yes, @jfcherng is right regarding the abilty to set the date and this might be what you wish to do… nonetheless this won’t “change” the commit but create a new one.

0 Likes

#3

Theoretically,

  • Commit date can be assigned by the GIT_COMMITTER_DATE env variable.
  • Author date can be assigned by the --date argument or by the GIT_AUTHOR_DATE env variable.

So both assigning their original dates means no change but that sounds tedious.

Ref: https://stackoverflow.com/a/5017265/4643765

2 Likes

#4

As far as I know, the git commit --amend --no-edit from the link should already allow to add changes to the last commit, while preserving the commit message and also the commit date. Of course you will then have to force push, if you already have pushed the original commit to a remote.

0 Likes

#5

It preserves author date but changes commit date. You can verify that with git show --format=fuller.

0 Likes