这个问题是基于线程的。
我目前有以下 Git 提示。cd
转到非 Git 文件夹后,我收到以下警告。
fatal: Not a git repository (or any of the parent directories): .git
fatal: git diff [--no-index] takes two paths
fatal: Not a git repository (or any of the parent directories): .git
fatal: git diff [--no-index] takes two paths
我当前在 Zsh 中的 Git-prompt 代码
# get the name of the branch we are on
git_prompt_info() {
ref=$(git symbolic-ref HEAD | cut -d'/' -f3)
echo $ref
}
get_git_dirty() {
git diff --quiet || echo '*'
}
autoload -U colors
colors
setopt prompt_subst
PROMPT='%{$fg[blue]%}%c %{$fg_bold[red]%}$(git_prompt_info)$(get_git_dirty)%{$fg[blue]%} $ %{$reset_color%}'
问题是以下代码导致非 Git 文件夹的警告
get_git_dirty() {
git diff --quiet || echo '*'
}
我试图通过将错误重定向到 /tmp/ 来解决该错误,但失败了
get_git_dirty() {
git diff --quiet 2>/tmp/error || echo '*' 2>/tmp/error
}
如何摆脱非 git 目录的警告消息?