例如,在一台新的ubuntu机器上,我刚刚运行了sudo apt-get git,在输入例如git check[tab]时没有完成。
我在http://git-scm.com/docs上没有找到任何东西,但IIRC完成是包含在这些天的git包中,我只需要在我的bashrc中正确的条目。
例如,在一台新的ubuntu机器上,我刚刚运行了sudo apt-get git,在输入例如git check[tab]时没有完成。
我在http://git-scm.com/docs上没有找到任何东西,但IIRC完成是包含在这些天的git包中,我只需要在我的bashrc中正确的条目。
当前回答
可能对某人有帮助:——
下载完。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_ps1是在git-prompt.sh中定义的。类似于下载。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是区分大小写的。
其他回答
Ubuntu 14.10
安装git-core和bash-completion
sudo apt-get install -y git-core bash-completion
对于当前会话使用情况 源/usr/share/bash-completion /完成/ git 在所有会议上都开着 Echo "source /usr/share/bash-completion/completion /git" >> ~/.bashrc
你看到的大多数说明都会告诉你如何下载
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
在你的bash启动脚本中,比如。bashrc。
但这有一个问题,因为它引用的是主分支,这是git-completion.bash的最新版本。问题是有时它会崩溃,因为它与你安装的git版本不兼容。
事实上,现在它将被打破,因为主分支的git-completion。Bash有需要git v2.18的新特性,包管理器和安装程序还没有更新到git v2.18。你会得到一个错误未知选项:——list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
因此,最安全的解决方案是引用与您安装的git匹配的版本/标记。例如:
https://raw.githubusercontent.com/git/git/v2.17.1/contrib/completion/git-completion.bash
注意,它有一个v2.17版本。而不是master。然后,当然,要确保在bash启动脚本中提供源代码。
在Linux上
在大多数发行版中,git完成脚本安装在/etc/bash_completion中。D /(或/usr/share/bash-completion/completion /git)安装git时,不需要去github。你只需要使用它-添加这一行到你的.bashrc:
source /etc/bash_completion.d/git
# or
source /usr/share/bash-completion/completions/git
在某些版本的Ubuntu中,默认情况下git自动完成可能会被破坏,通过运行这个命令重新安装应该可以修复它:
sudo apt-get install git-core bash-completion
在Mac
您可以使用Homebrew或MacPorts安装git完成。
家酿
if $BASH_VERSION > 4: brew install bash-completion@2(更新版本) 请特别注意您使用的bash版本,因为MacOS默认附带3.2.57(1)-release。
添加到.bash_profile:
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
对于旧版本的bash: brew安装bash-completion
添加到.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
MacPorts
Sudo端口安装git +bash_completion
然后把这个添加到你的.bash_profile中:
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
fi
更多信息在本指南:安装Bash git完成
注意,在所有情况下,您都需要创建一个新的shell(打开一个新的终端选项卡/窗口),以便更改生效。
可能对某人有帮助:——
下载完。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_ps1是在git-prompt.sh中定义的。类似于下载。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是区分大小写的。
Arch Linux
/usr/share/git/completion/git-completion来源。在其中一个Bash启动文件中。
例如:
# ~/.bashrc
source /usr/share/git/completion/git-completion.bash
你可以在/usr/share/bash-completion/completions/git等其他位置找到该脚本,但这些脚本对我不起作用。