Is it possible to update the commit Id without creating a new commit in Git

·

2 min read

Hello there :)

A few days back I was on a mission to change the commit id of a commit.

This is how it started. I had a new file file1.txt which I had to upload in my source tree. I quickly did the time tested way to commit this file.

      1. git add file1.txt
      2. git commit
      3. My notepad++ editor opened for me to type a commit Header and message.

After this a git status was enough to let me know that my 'branch was ahead of origin by 1 commit'

At this point I had an idea. I wanted to change the commit Id of the existing commit without changing any other properties.

Later I edited my commit message and header. This I established by 'git commit --amend'. I changed both the Header and the message. Even though both the commit message and header were changed the commit's Id still remained the same.

So, I resorted to trying it out the other way. I used the git commit -m "New commit message".

I had this statement in the message. 'nothing added to commit but untracked files present'.

After this I did a git commit --amend to verify if the new message was written to the said commit. The git commit -m didn't affect the old commit id,header or the message.

My conclusion is that git commit -m above an existing commit without adding any file changes has no effect on the commit Id. The git commit -m also fails without changing the commit message to a newer message.

I am a beginner and I am still looking for ways to only change the commit Id of an existing commit. If you know of any ways, please drop a comment :)

Have a nice day. Bye :)