I have a script whose last line is:
git diff --no-index -- ./a.json ./b.json > ./a-b.diff
diff returns an exit code of 1
when the files differ, which causes my script to report an error.
How can I ignore the exit code from diff, but retain the output redirect of the content to the diff file?
Try:
git diff --no-index -- ./a.json ./b.json > ./a-b.diff || true
Or :
git diff --no-index -- ./a.json ./b.json > ./a-b.diff || :
Or, as long as you aren't using bash -e
:
git diff --no-index -- ./a.json ./b.json > ./a-b.diff
true
Basically, you can use any command after the diff that you know will produce a zero (success) exit code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With