git - 获取没有慢速差异列表的 git status boolean

标签 git

如果我的 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 --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 boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35375186/

相关文章:

python - 如何为现有 GitHub 存储库创建 Xcode 项目

Git网站部署

git - 将一个本地分支 merge 到另一个本地分支

git - 什么是 "not something we can merge"错误?

ios - 查看 StreamingKit 的 git 存储库时遇到问题

Git 不允许我切换分支

git - 哪个提交有这个 Blob ?

git - 只获取已经 merge 到 master/develop 的远程分支

ios - 我无法让 cocoapods 下载正确的提交

git - 将 git 服务器作为 CGI 运行?