如果我的 git 目录发生变化,我有一个 bash PS1 会变成红色,如果没有发生变化,我会变成绿色。
if [ $? -eq 0 ]; then \
echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \
if [ "$?" -eq "0" ]; then \
# @4 - Clean repository - nothing to commit
echo "\n'$Green'"$(__git_ps1 "(%s)"'$Color_Off'); \
else \
# @5 - Changes to working tree
echo "\n'$IRed'"$(__git_ps1 "(%s)"'$Color_Off'); \
fi)\$ "; \
fi)'
这很好用! 但问题是,在某些工作中,目录非常慢,因为存在许多变化和很大的差异。
在没有完整的情况下获取 git status boolean(是更改或未更改)的更好方法是什么
我尝试使用 git status --short
或 git status --porcelain
但还是很慢。
最佳答案
也许这个答案可能有用:https://stackoverflow.com/a/2659808/3903076
简而言之,您可以根据自己的需要调整以下检查。有关详细信息,请参阅链接的答案。
if ! git diff-index --quiet --cached HEAD; then
# Index has changes.
exit 1;
elif ! git diff-files --quiet; then
# Working tree has changes.
exit 1;
elif [ -n "`git ls-files --others --exclude-standard`" ]; then
# There are untracked unignored files.
exit 1;
fi
关于git - 获取没有慢速差异列表的 git status boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35375186/