Reputation: 43
I need to detect if there are any changes staged to commit for a new GIT
repository via a shell script.
git diff --cached HEAD
Above command returns 0
when changes are staged, but requires a HEAD
. If it cannot find one, it returns 128
(in case of new repository).
So How to detect if there were changes staged for a new repo and whether I need to commit?
If I try to commit
when there are no changes to commit, it exits with return code 1
.
I am not sure if I can use this fact.
Does commit return 1
IF AND ONLY IF there are no changes to commit?
I couldn't find any documentation supporting this.
Note: I am not trying to auto-commit when a file is changed, I am aware I can use inotifywait
for that.
Upvotes: 0
Views: 99