この質問はスレッドに基づいています。
現在、次の 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 プロンプトの現在のコード
# 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 ディレクトリの警告メッセージを取り除くにはどうすればよいですか?