How to git commit nothing without an error? How to git commit nothing without an error? python python

How to git commit nothing without an error?


Catch this condition beforehand by checking the exit code of git diff?

For example (in shell):

git add -Agit diff-index --quiet HEAD || git commit -m 'bla'

EDIT: Fixed git diff command according to Holger's comment.


From the git commit man page:

--allow-empty    Usually recording a commit that has the exact same tree as its    sole parent commit is a mistake, and the command prevents you    from making such a commit. This option bypassesthe safety, and    is primarily for use by foreign SCM interface scripts.


with settings(warn_only=True):  run('git commit ...')

This causes fabric to ignore the failure. Has the advantage of not creating empty commits.

You can wrap it in a additional layer of with hide('warnings'): to totally suppress output, otherwise you'll get a note in the fabric output that the commit failed (but the fabfile continues to execute).