How can I check, in a script, if local changes are present? Perhaps in combination with git describe?
How can I check, in a script, if local changes are present? Perhaps in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You will need to make sure that both the two following properties are met:
That there are no differences between HEAD and the index cache
git diff-index --cached HEADThat there are no differences between the index and the working tree:
git diff-filesBoth commands take a
--quietparameter which will set the exit code according to whether there are differences or not (starting some time after git 1.4). If you need to make it work on git 1.4, you need to run the commands without--quietand check whether they produce any output.Note:
git diffis a porcelain command, and thus should not be used in scripts. Use above plumbing commands instead.Example shell code, taken from my git_version.sh script:
If you can require a git version >= 1.5,
if git diff-files --quiet && git diff-index --quiet --cached HEAD; thencan replace above comparison.Note: This solution (exactly like Antony’s interactive
git diff HEAD --quiet) only discovers local changes relative to HEAD. However, local commits can arguable also be considered local changes, and naturally will not show up in any diff against HEAD. You will need to check the SHA1 valuegit describeuses to detect whether HEAD is from a set of commits you consider not to be local changes.