git 初始化git存储库
How to test whether the git repository is dirty?
如何测试git 存储库是否脏?
git status can show this. But how to diagrammatically detect this in bash?
git status可以显示这一点。 但是如何在bash中以图形方式检测到这一点呢?
This piece of bash code works like a charm for me:
这段bash代码对我来说就像一个魅力:
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]
You can use it to build your script.
您可以使用它来构建脚本 。
For example, print “dirty” or “clean”:
例如, 打印 “脏”或“干净”:
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
echo "dirty"
else
echo "clean"
fi
Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。
翻译自: https://www.systutorials.com/how-to-test-whether-the-git-repository-is-dirty/
git 初始化git存储库