

清除 zsh steeef 主题的未追踪标记
source link: https://blog.yxwang.me/2013/01/cleaning-zsh-vcs-status/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

清除 zsh steeef 主题的未追踪标记
Thu, Jan 24, 2013 • Tooling
我用的 zsh 提示符是 oh-my-zsh 自带的 steeef。最近发现用这个主题时,有些 Rails 项目即使把所有改动都提交后,还是会有红色标记表示存在未追踪文件:
使用 git status
和 git diff
,都看不到任何未提交的改动。一开始我以为是 zsh 或者 git 的 bug,把它们的版本都更新到最新版后还是有这个问题。于是看 steeef 主题的源码,发现了红色标记的判断依据:
# check for untracked files or updated submodules, since vcs_info doesn't
if git ls-files --other --exclude-standard --directory 2> /dev/null | grep -q "."; then
PR_GIT_UPDATE=1
FMT_BRANCH="(%{$turquoise%}%b%u%c%{$hotpink%}●${PR_RST})"
else
FMT_BRANCH="(%{$turquoise%}%b%u%c${PR_RST})"
fi
因为 vcs_info 没有提供未追踪文件或模块的方法,作者在这里用了 git ls-files --other --exclude-standard --directory
检测当前项目是否包含未追踪的文件,而在我的项目根目录下运行这个命令后,可以看到有三个目录未被追踪:
$ git ls-files --others --exclude-standard --directory
log/
public/system/
tmp/
这几个目录在 .gitignore 中都有声明,当时项目刚创建时借用了 gitignore 中的模版,相关的声明是:
/log/*
/tmp/*
/public/system/*
看来问题就出在这里用了通配符 *,把目录下的所有文件而不是目录本身忽略了。因为 git 不允许把空目录加到项目中,git status
和 git ignore
都不会显示这些目录,而作者检测时用的 git ls-files --directory
又会包含未追踪的空目录,就出现了这个提示有改动却找不到的情况。知道问题后解决方案很简单,把 .gitignore 文件中的 xxx/*
都改成 xxx/
,或者把 --directory
参数去掉就好了。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK