例如,在一台新的ubuntu机器上,我刚刚运行了sudo apt-get git,在输入例如git check[tab]时没有完成。

我在http://git-scm.com/docs上没有找到任何东西,但IIRC完成是包含在这些天的git包中,我只需要在我的bashrc中正确的条目。


当前回答

我也有同样的问题,遵循以下步骤:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

然后将以下行添加到.bash_profile(通常在您的主文件夹下)

if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi

来源:http://code-worrier.com/blog/autocomplete-git/

其他回答

Mac M1

对于那些使用Mac M1环境的用户,我可以通过自制软件进行安装:

酿造安装bash-completion

然后添加到我的~/。Bash_profile或~/。Bashrc(不管你用什么):

[[ -r "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh"

您可能需要更新版本号(1.3_3)。你只需要在那个目录中查找即可。我很想知道有没有更好的办法。

Arch Linux

/usr/share/git/completion/git-completion来源。在其中一个Bash启动文件中。

例如:

# ~/.bashrc

source /usr/share/git/completion/git-completion.bash

你可以在/usr/share/bash-completion/completions/git等其他位置找到该脚本,但这些脚本对我不起作用。

在Github的Git项目中,他们提供了一个bash文件来自动完成Git命令。

您应该将其下载到主目录,并强制bash运行它。这只是简单的两个步骤,并在接下来的博客文章中完美地解释(一步一步地)。

代码担忧者博客:autocomplete-git/

我已经在mac上测试过了,它应该也能在其他系统上工作。您可以将相同的方法应用于其他操作系统。

我也有同样的问题,遵循以下步骤:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

然后将以下行添加到.bash_profile(通常在您的主文件夹下)

if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi

来源:http://code-worrier.com/blog/autocomplete-git/

只需在~/.bashrc中这样做:

source /usr/share/bash-completion/completions/git

其他答案告诉你安装bash-completion,你不需要这样做,但如果你这样做,那么就不需要直接源完成。你只能做其中一个,不能两个都做。

一个更通用的解决方案是查询bash-completion项目推荐的系统位置:

source "$(pkg-config --variable=completionsdir bash-completion)"/git