简体   繁体   English

如何将自动完成功能添加到git别名?

[英]How do I add autocomplete to git aliases?

I have setup git autocomplete using the git-autocomplete.bash file which works for standard commands and simple aliases ( co = checkout ), but I have a longer alias defined in my .git-config file that I would like to autocomplete branch names on and I cannot find how to do this. 我已经使用git-autocomplete.bash文件设置了git autocomplete,该文件适用于标准命令和简单别名( co = checkout ),但是我在.git-config文件中定义了一个较长的别名,我希望在该文件上自动完成分支名称。我找不到如何做到这一点。

I am on Windows Server 2012 R2 running git 2.10.2.windows.1 我在运行git 2.10.2.windows.1的Windows Server 2012 R2上

My alias looks like this: 我的别名如下所示:

mstage = "!git checkout stage && git pull && git reset --hard && git merge $1 --no-commit"

where $1 is a branch name - I'd love this to autocomplete 其中$1是分支机构的名称-我希望它可以自动完成

here we have two options for windows operating system: 这是Windows操作系统的两个选项:

msysgit msysgit

  1. Download and place git-flow-completion.bash in home directory ( ~/ in msysgit shell) 下载git-flow-completion.bash并将其放在主目录中( ~/在msysgit shell中)
  2. Add a .bashrc file to your home directory with the following line (or add this line to existing .bashrc file): 使用以下行将.bashrc文件添加到您的主目录中(或将此行添加到现有.bashrc文件中):

    source ~/git-flow-completion.bash 源〜/ git-flow-completion.bash

Cygwin 西格温

  1. Download and place git-flow-completion.bash in 下载并将git-flow-completion.bash放入

    %CYGWIN_INSTALLATION_DIR%\\etc\\bash_completion.d

  2. Rename it to git-flow 将其重命名为git-flow

    you can autocomplete as following: git flow init etc. 您可以如下自动完成: git flow init等。

@Rohit Poudels answer works if you are using bash on Windows. 如果您在Windows上使用bash,则@Rohit Poudels答案有效。 If you are using PowerShell, currently the only way to enable this autocomplete is to change posh-git manually after installing. 如果使用的是PowerShell,当前启用此自动完成功能的唯一方法是在安装后手动更改posh-git。

I changed the GitTabExpansion.ps1 file in posh-git, similarly to what is outlined on the repo . 我在posh-git中更改了GitTabExpansion.ps1文件,类似于repo中概述的内容

More specifically, I added $line = $line -replace '^git mstage ', 'git checkout ' as the first line in the function TabExpansion which will in effect will treat my alias as equivalent to git checkout and tab expansion will then behave as expected 更具体地说,我在功能TabExpansion的第一行中添加了$line = $line -replace '^git mstage ', 'git checkout ' ,这实际上将把我的别名视为与git checkout等效,然后Tab扩展将表现为预期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM