Bash git 别名选项卡完成错误
我知道 Git 别名可以与参数一起使用 Git 常见问题解答部分“带参数的 Git 别名”< /a>.
但今天我遇到了一个错误。
举一个简单的例子,它不适合实际使用。如果我创建一个像这样的别名:
[alias]
lo = "!sh -c 'git log $1' -"
那么我可以用来
git lo file_a
查看 file_a 的日志。
但是当我使用“tab”自动完成路径时,出现以下错误。
git lo [tab]
错误消息:
sh: declare: `_git_{': not a valid identifier
这似乎是 git-completion.bash 中的一个错误。但我找不到`_git_{'在哪里!
我还发现在错误消息中 _git_{ 周围的引号看起来很奇怪。
顺便说一句,我的 msysgit 版本是 1.7.6-preview20110708
ADD:
另一个奇怪的事情是,我搜索了 Git 目录下的所有文件,发现没有文件包含字符串_git_{。
I know Git aliases can be used with arguments Git Faq section "Git Aliases with argument".
But today I encountered an error.
Take an easy example which is not suitable for real use. If I make an alias like this:
[alias]
lo = "!sh -c 'git log $1' -"
then I can use
git lo file_a
to see the log of file_a.
But when I used "tab" to auto-complete the path, the following error occurs.
git lo [tab]
error msg:
sh: declare: `_git_{': not a valid identifier
It seems a bug in git-completion.bash. But I can't find where the `_git_{' is!
Also I find that in the error msg the quote mark around _git_{ seems strange.
BTW, my msysgit version is 1.7.6-preview20110708
ADD:
The other strange thing is, I searched all files under the dir of Git, find there is no file contains the string _git_{.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了完全相同的问题。例如,我有一个用于一次性删除本地分支及其远程对应分支的别名:
为了解决该问题,我删除了该别名并将名为 git-db 的文件添加到我的 Git 脚本中目录。它可以是 PATH 中的任何目录。这是文件的内容。
请注意,该文件不得有扩展名。它可以像别名一样使用:
I had the exact same problem. For example, I had an alias for deleting a local branch and its remote counterpart in one go:
In order to fix the problem, I removed the alias and added a file named git-db to my Git scripts directory. It can be any directory in the PATH. Here's the contents of the file.
Note that the file must not have an extension. It can be used just like the alias:
我猜想为 git 设置了一个自定义完成功能,错误就在该设置中。首先尝试删除自定义完成,看看错误是否消失:
旁注:对于 git 别名中具有可重用参数的 shell 命令,现代习惯用法是定义一个 shell 函数,它允许您使用标准 shell 参数处理并减少一个级别与“sh -c”相比要处理的参数引用:
I'm guessing there's a custom completion function set up for git, and the error is in that setup. Try removing the custom completion first and see if the error disappears:
Side note: for shell commands with reusable arguments in a git alias, the modern idiom is to define a shell function, which lets you use standard shell argument processing and has one fewer levels of argument quoting to deal with when compared to 'sh -c':
此错误是由于旧版本的 Git 附带的 bash 完成脚本中的缺陷造成的。它不是为处理 shell 别名而设计的,这导致了此错误。此问题已在 commit 56f24e80f0 中修复,但直到 Git 2.1.0 才包含此更改。然而,截至撰写本文时,msysGit 仍在 Git 1.9.5 上,因此不包含修复程序。
首选解决方案是切换到 Git for Windows,它是 msysGit 的后继者,它跟踪当前的Git 发布。
但是,如果您坚持使用旧版本的 Git,您仍然可以通过用自定义脚本替换别名来解决该问题,如 @Reinhard Nägele 的回答。
This error is due to a shortcoming in the bash completion script that shipped with older versions of Git. It was not designed to handle shell aliases, which caused this error. This was fixed in commit 56f24e80f0, but this change was not included until Git 2.1.0. However, msysGit is as of this writing still on Git 1.9.5 and thus does not include the fix.
The preferred solution is to switch to Git for Windows, the successor to msysGit, which tracks current Git releases.
However, if you are stuck with an old version of Git, you can still work around the problem by replacing the alias with a custom script, as described in the answer by @Reinhard Nägele.