OP的问题现在已经超过9年了。我不知道当时man git-status说了什么,但是现在是这样说的:
--porcelain[=<version>]
Give the output in an easy-to-parse format for scripts. This is similar to the
short output, but will remain stable across Git versions and regardless of user
configuration. See below for details.
The version parameter is used to specify the format version. This is optional and
defaults to the original version v1 format.
这表明该--porcelain参数非常适合测试回购状态以进行更改。
关于OP的问题是:“是否有某种布尔检查自上次提交以来是否有更改,或者我该如何真正测试本地存储库是否有新更改?”
我不认为它本身bash具有布尔数据类型,但这可能足够接近:
[ -z "`git status --porcelain`" ] && echo "NULL-NO DIFFS" || echo "DIFFS EXIST"
可以将其重新生成为if-then-else脚本的表单,也可以在git repo文件夹中按CLI的原样执行。否则,请将该-C选项与指向所需存储库的路径一起使用:
git -C ~/path/to/MyGitRepo status --porcelain
git status?