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??
Git makes this process of pushing an empty commit super simple. It's like pushing a regular commit, except that you add the --allow-empty flag. You can see that the commit has been pushed to your branch without any changes after running the above commands.
On Windows this command git commit -a --allow-empty-message -m '' makes commit with commit message " '' ", so it is better to use this command instead: git commit -a --allow-empty-message -m "" .
provided <remotebranchname> already exists on the remote. (If it doesn't, you can use git push <remotename> <commit SHA>:refs/heads/<remotebranchname> to autocreate it.) If you want to push a commit without pushing previous commits, you should first use git rebase -i to re-order the commits.
Typically pushing and pulling a few times a day is sufficient. Like @earlonrails said, more frequent pushes means less likelihood of conflicting changes but typically it isn't that big a deal. Think of it this way, by committing to your local repository you are basically saying "I trust this code. It is complete.
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"
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.
pushing commits, whether empty or not, causes eventual git hooks to be triggered. This can do either nothing or have world shattering consequences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With