Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing empty commits to remote

Tags:

git

git-commit

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??

like image 505
mrutyunjay Avatar asked Nov 22 '13 06:11

mrutyunjay


People also ask

Can you push an 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.

How do you push a commit without text?

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 "" .

How do I push a specific commit to a remote?

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.

How often should you push your 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.


3 Answers

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"
like image 86
sarjit07 Avatar answered Oct 20 '22 07:10

sarjit07


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.

like image 40
Gabriele Petronella Avatar answered Oct 20 '22 08:10

Gabriele Petronella


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

like image 41
xor Avatar answered Oct 20 '22 07:10

xor