可能对某人有帮助:
从以下链接下载.git-completion.bash后,
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
并试图使用__git_ps1函数,我得到错误 –
-bash: __git_ps1: command not found
显然我们需要从master下载脚本来使这个命令起作用,因为在git-prompt.sh中定义了__git_ps1。 和下载.git-completion.bash类似,得到git-prompt.sh:
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
然后在.bash_profile中添加以下内容
source ~/.bash_git if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash export PS1='\W$(__git_ps1 "[%s]")>' fi
源〜/ .bash.git将执行下载的文件和
export PS1='\W$(__git_ps1 "[%s]")命令将在当前工作目录(如果它是一个git存储库)之后附加检出分支名称。
所以它会看起来像:
dir_Name[branch_name]其中dir_Name是工作目录名称,branch_name将是您当前正在使用的分支的名称。
请注意 – __git_ps1区分大小写。