【问题标题】:Zsh in iTerm2 completion causing git push erroriTerm2中的zsh完成导致git push错误
【发布时间】:2017-10-18 18:41:30
【问题描述】:

我正在将 Zsh 与 iTerm2 一起使用,并尝试关注 these instructions 以删除我不小心推送到存储库的提交(别担心,它除了我之外没有任何关注者)。

运行命令

git push -f origin HEAD^:develop

导致 Zsh 出错

error: src refspec HEADER does not match any.
error: failed to push some refs to 'git@github.com:xxx/yyy.git'

此目录中有一个名为 HEADER 的文件,所以我认为 Zsh 或 iTerm 试图通过使用 ^ 完成一些功能来变得更聪明。

我在 Terminal.app 中执行了相同的推送命令(仍然使用 /bin/sh)并且它起作用了。

这是什么 Zsh/iTerm 行为以及如何控制它?

【问题讨论】:

  • 你试过git push -f origin "HEAD^":develop(带引号)
  • 你也可以使用HEAD~,这是等效的。

标签: git github zsh iterm2 zsh-completion


【解决方案1】:

我怀疑 zsh 正在尝试扩展 HEAD^:develop,这是一个有效的 glob 模式并且与 HEADER 文件准确匹配。

一个简单的解决方案是将参数括在引号中,这将防止 zsh “有用”并为您扩展这些通配模式:

git push -f origin "HEAD^":develop

您还可以转义有问题的字符(如git-rm 的文档中所建议的那样):

git push -f origin HEAD\^:develop

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    • 2014-10-26
    相关资源
    最近更新 更多