'Pushing empty commits to remote

I have pushed one commit to remote but now I realized that the commit message is not correct. I would like to change the commit message but AFAIK it is not possible. So i decided to create empty commit with correct message:

git commit --allow-empty

Are there any disadvantages/consequences of pushing empty commits? Is there any problem I might face in future because of this empty commit??



Solution 1:[1]

One use of an empty commit would be to force a build to occur in an environment where builds are triggered whenever new commits are pushed.

git commit --allow-empty -m "Trigger Build"

Solution 2:[2]

You won't face any terrible consequence, just the history will look kind of confusing.

You could change the commit message by doing

git commit --amend
git push --force-with-lease # (as opposed to --force, it doesn't overwrite others' work)

BUT this will override the remote history with yours, meaning that if anybody pulled that repo in the meanwhile, this person is going to be very mad at you...

Just do it if you are the only person accessing the repo.

Solution 3:[3]

pushing commits, whether empty or not, causes eventual git hooks to be triggered. This can do either nothing or have world shattering consequences.

Solution 4:[4]

Is there any disadvantages/consequences of pushing empty commits?

Aside from the extreme confusion someone might get as to why there's a bunch of commits with no content in them on master, not really.

You can change the commit that you pushed to remote, but the sha1 of the commit (basically it's id number) will change permanently, which alters the source tree -- You'd then have to do a git push -f back to remote.

Solution 5:[5]

As long as you clearly reference the other commit from the empty commit it should be fine. Something like:

Commit message errata for [commit sha1]

[new commit message]

As others have pointed out, this is often preferable to force pushing a corrected commit.

Solution 6:[6]

As for confusing history I have a proposal for eventually making life of future archeologists easier.

git commit --allow-empty -m "message for commit DEADBEF was wrong. Correct Msg: ..."

where DEADBEF stands for the commit hash (SHA) of the commit with the wrong message.

Or if empty commit is not possible/allowed one could create a document

commitcomments/$SHA.txt

add/commit it and push it.

BTW: Cant resist to let on that git history is very often confusing anyway :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M. Justin
Solution 2
Solution 3 xor
Solution 4 yamafontes
Solution 5 153957
Solution 6