git stash@{1} 不明确?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6468893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:36:48  来源:igfitidea点击:

stash@{1} is ambiguous?

git

提问by Uncommon

I'm trying to get info about my stash, but git is telling me that stash@{0}and stash@{1}are ambiguous. git stash listworks fine, and .git/logs/refs/stashseems to have the appropriate content (not that I'm an expert on git internals).

我正在尝试获取有关我的藏匿处的信息,但是 git 告诉了我stash@{0}并且stash@{1}模棱两可。git stash list工作正常,并且.git/logs/refs/stash似乎有适当的内容(并不是说我是 git 内部的专家)。

% git stash list
stash@{0}: On master: two
stash@{1}: On master: one
% git stash show stash@{1}
fatal: ambiguous argument 'stash@1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

Just plain git stash showworks fine. So why are the names that git stash listgives me considered ambiguous?

只是简单的git stash show工作正常。那么为什么git stash list给我的名字被认为是模棱两可的呢?

回答by Jan Hudec

Your shell is eating your curly brackets, so while you say stash@{1}, git sees stash@1and that makes no sense to it. Quote the argument (use git stash apply "stash@{1}"or git stash apply stash@"{1}"; quoting either way will work) or reconfigure your shell to only expand curly brackets when there is a comma between them (zsh can be configured either way, bash only expands curly brackets with comma or range between them, other shells may behave one or other way).

你的外壳正在吃你的大括号,所以当你说stash@{1}git 时stash@1,这对它没有意义。引用参数(使用git stash apply "stash@{1}"git stash apply stash@"{1}"; 引用任何一种方式都可以)或重新配置您的 shell 以仅在大括号之间有逗号时展开大括号(zsh 可以以任何一种方式配置,bash 仅使用逗号或它们之间的范围来扩展大括号,其他shell 可能会以一种或其他方式运行)。

回答by d.f

Hi there I had the same thing happen to me. Easiest way of fix it was:

你好,我也遇到了同样的事情。最简单的修复方法是:

$ git stash apply stash@"{2}"

I'm using a windows git shell.

我正在使用 Windows git shell。

回答by user3251328

For zsh users:

对于 zsh 用户:

$ git stash apply stash@'{'1'}'

回答by Adriano

Simply put stash id between simple quotes:

只需将 stash id 放在简单的引号之间:

git stash apply 'stash@{1}'

回答by Sergey

If you have this error while working in Emacs with Magit on Windows (like me)
I hope this quick solution will help you:

如果您在 Windows 上使用 Magit 使用 Emacs 工作时遇到此错误(像我一样),
我希望这个快速解决方案可以帮助您:

(if (eq system-type 'windows-nt)
    (defadvice magit-run-git (before magit-run-git-win-curly-braces (&rest args) activate)
      "Escape {} on Windows"
      (setcar (nthcdr 2 args) 
              (replace-regexp-in-string "{\([0-9]+\)}" "\\{\1\\}" (elt args 2)))
    )
  )

This will quote {}in a 3rd parameter in ("stash", "cmd", "stash@{0}")which is run by magit-run-git

这将引用由运行{}的第三个参数("stash", "cmd", "stash@{0}")magit-run-git