我看到git
alias
是很奇怪的东西。使用Tab键获取自动完成的git
命令时,出现bash
错误。例如,如果我键入git pu
以查看所有选项,则会发生这种情况:
$ git pu-bash: remote: command not found
-bash: -v: command not found
-bash: command substitution: line -327: syntax error near unexpected token `|'
-bash: command substitution: line -327: `| '
-bash: usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]: command not found
-bash: rev-parse: command not found
-bash: usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]: command not found
-bash: usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]: command not found
-bash: brname: command not found
-bash: brname: command not found
-bash: brname-trimmed: command not found
-bash: brname-trimmed: command not found
-bash: ls-files: command not found
-bash: @{u}: command not found
终端将几行卡在上面的输出中,并且^C
多次打印了所有错误行之后。
我不确定错误指向哪个文件的行号,即我在alias
中的~/.gitconfig
在行174处结束。我注释掉了任何在错误中具有其名称的别名列表(例如brname
)或使用列出的git
命令(例如内置rev-parse
出现错误)。直到错误消息消失并且自动完成再次开始工作为止。
现在,如果我输入git pu
并按Tab键,我会处于以下状态:
$ git pu
pull pull push push
请注意,此处的响应加倍,对于其他任何输入,请按Tab键。
我注释掉以获得良好状态的别名之一是:
brname-trimmed = !git rev-parse --abbrev-ref HEAD | tr -d '\n'
假设我在标签T1上
- 如果我打开新标签页T2,取消注释T1上的别名,然后保存文件,则可以使用git自动完成,而在T2上没有任何问题。
- 如果取消注释别名,请保存文件,然后打开一个新标签T2并在T2上键入
git pu
,我看到:
$ git pu-bash: : command not found
-bash: command substitution: line -166: syntax error near unexpected token `&&'
-bash: command substitution: line -166: `&& '
我的~/.gitconfig
的第166行既没有:
也没有&&
,甚至被注释掉了。
- 如果我取消注释别名,然后将其更改为
xbrname-trimmed
(只需在开头添加x,所以它是一个不同的单词),则无论T2何时打开,自动补全效果都很好。
我正在使用几个月未完成开发工作的机器,因此不确定何时发生此问题。 git版本是2.22.0