如果我的git dir更改,我的bash PS1将变为红色;如果未更改,我将变为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 bool 值(是更改还是不更改)的更好方法
我尝试了git status --shortgit 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 bool 值而没有比较慢的列表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35375186/

10-14 16:21
查看更多