[英]“bash: __gitdir: command not found” error in terminal
Whenever I'm working in the command window, I get the error: "bash: __gitdir: command not found" right above the working line (in other words, right after any command, before it prompts for a new one). 每当我在命令窗口工作时,我得到错误:工作线正上方的“bash:__ gitdir:command not found”(换句话说,在任何命令之后,在它提示新的命令之前)。
Any ideas as to what is going on to bring this up? 有什么想法可以提出这个问题吗?
__gitdir
is a function supplied by the git-completion.bash
script that lets bash do auto-complete when you type git
commands. __gitdir
是git-completion.bash
脚本提供的一个函数,它允许bash在你输入git
命令时自动完成。 Are you using __gitdir
in your .bashrc
or other profile/login script without sourcing git-completion.bash
? 您是否在
.bashrc
或其他配置文件/登录脚本中使用__gitdir
而没有采购git-completion.bash
?
You probably have something calling that command in your .bashrc
file. 您可能在
.bashrc
文件中调用了该命令。
Try searching for __gitdir in it: 尝试在其中搜索__gitdir:
$ grep __gitdir ~/.bashrc
Or maybe post its content, and it will probably be easier to help. 或者发布其内容,它可能会更容易提供帮助。
The fancy git prompt may be enabled via the function __git_ps1
, which can be embedded in PS1
and called every time your prompt is printed. 可以通过函数
__git_ps1
启用花哨的git提示,该函数可以嵌入到PS1
并在每次打印提示时调用。 It's defined when sourcing a specific, but potentially different file than the one that defines __gitdir
. 它是在定义特定但可能不同于定义
__gitdir
文件时定义的。 The __git_ps1
(which calls __gitdir
) could be in perhaps /etc/bash_completion.d/git-prompt
or /usr/share/git-core/contrib/completion/git-prompt.sh
or /etc/bash_completion.d/git
(etc)... __git_ps1
(调用__gitdir
)可能在/etc/bash_completion.d/git-prompt
或/usr/share/git-core/contrib/completion/git-prompt.sh
或/etc/bash_completion.d/git
(等等)...
But if __git_ps1
ends up getting defined, but __gitdir
does not, then you would get this error (every time your prompt is printed). 但是如果
__git_ps1
最终定义,但__gitdir
没有定义,那么你会得到这个错误(每次打印你的提示)。 For example, if __gitdir
is defined in /etc/*
, but __git_ps1
is found in /usr/share/*
, then in a chroot env you may end up with __git_ps1
defined but __gitdir
not defined. 例如,如果
__gitdir
中定义/etc/*
,但__git_ps1
被发现/usr/share/*
,然后在chroot ENV你可能会最终__git_ps1
定义,但__gitdir
没有定义。
To "quiet" the error message, either remove the fancy git prompt, or just define it: __gitdir() { :; }
要“安静”错误消息,请删除花哨的git提示符,或者只是定义它:
__gitdir() { :; }
__gitdir() { :; }
This will not exactly address the original question context, but might be useful for newer Ubuntu users migrating from older versions... 这不会完全解决原始问题上下文,但可能对从较旧版本迁移的较新Ubuntu用户有用...
I recently upgraded an old Ubuntu 12.04 machine to newer version of Ubuntu and I started seeing errors about __git_dir
missing due to my PS1
settings like explained by the other answers. 我最近将一台旧的Ubuntu 12.04机器升级到了更新版本的Ubuntu,我开始看到由于我的
PS1
设置而错过__git_dir
错误,如其他答案所解释的那样。 To understand why this shell function was not any more defined I figured my .bashrc
was not up-to-date with the newer Ubuntu conventions. 为了理解为什么这个shell函数没有被定义,我认为我的
.bashrc
与最新的Ubuntu约定不是最新的。
My old .bashrc
that was based on the one originally provided by old Ubuntu system had something similar to this: 我的旧
.bashrc
基于最初由旧的Ubuntu系统提供的那个有类似的东西:
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
while .bashrc
files created by newer Ubuntu systems first try to use /usr/share/bash-completion/bash_completion
: 由较新的Ubuntu系统创建的
.bashrc
文件首先尝试使用/usr/share/bash-completion/bash_completion
:
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
When I replaced the old bash completion sourcing with the newer one, I got __git_dir
defined and was happy ever after. 当我用新的替换旧的bash完成源时,我定义了
__git_dir
并且从此开心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.