关于gitbash一直报:sh: __git_ps1: command not found的解决办法
在使用set命令设置docker
的环境变量,
然后gitbash
一直报sh: __git_ps1: command not found
。
搜索了一番,并没有相似的解决办法。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在stackoverflow上找到灵感,就去
gitbash
的安装目录\Git\etc
搜寻了一番,找到了如下文件:bash.bashrc
其中有这么一行
我把
PS1
前面的#去掉,然后在输入sh,就没有报错了是因为__git_ps1未定义,
可以先初始化一下git-prompt环境变量.
例如:
source ~/.git-prompt.sh
虽然时隔多年,但是是被搜索的第一个,忍不住注册个账号来回答一下,为以后的同学踩坑有迹可循。
具体请参考:git-prompt.sh第12行
1 # bash/zsh git prompt support
2 #
3 # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
4 # Distributed under the GNU General Public License, version 2.0.
5 #
6 # This script allows you to see repository status in your prompt.
7 #
8 # To enable:
9 #
10 # 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
11 # 2) Add the following line to your .bashrc/.zshrc:
12 # source ~/.git-prompt.sh
13 # 3a) Change your PS1 to call __git_ps1 as
14 # command-substitution:
15 # Bash: PS1='[u@h W$(__git_ps1 " (%s)")]\$ '
16 # ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
17 # the optional argument will be used as format string.
18 # 3b) Alternatively, for a slightly faster prompt, __git_ps1 can
19 # be used for PROMPT_COMMAND in Bash or for precmd() in Zsh
20 # with two parameters, <pre> and <post>, which are strings
21 # you would put in $PS1 before and after the status string
22 # generated by the git-prompt machinery. e.g.
23 # Bash: PROMPT_COMMAND='__git_ps1 "u@h:w" "\$ "'
24 # will show username, at-sign, host, colon, cwd, then
25 # various status string, followed by dollar and SP, as
26 # your prompt.
27 # ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
28 # will show username, pipe, then various status string,
29 # followed by colon, cwd, dollar and SP, as your prompt.
30 # Optionally, you can supply a third argument with a printf
31 # format string to finetune the output of the branch status