Git |> Avoid Error When Nothing to Commit



IF YOU JUST SOLVED SOME PROBLEM, WELCOME TO DM qaRabbit ON TWITTER, OR CREATE A PULL REQUEST IN GITHUB REPO.

Checking the exit code of git diff

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

Not produce the correct result if there are differences only between the index and work tree.

Improve Answer:

git diff-index --quiet --cached HEAD || git commit -m 'bla'

Other solution:

git commit -m 'bla' --allow-empty

Not good enough, it would actually create a commit though.


Reference: