134

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

% 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 show works fine. So why are the names that git stash list gives me considered ambiguous?

Uncommon
  • 3,083
  • 2
  • 17
  • 35

5 Answers5

253

Your shell is eating your curly brackets, so while you say stash@{1}, git sees stash@1 and 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).

Jan Hudec
  • 69,456
  • 12
  • 118
  • 163
25

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.

Martin
  • 3,802
  • 7
  • 42
  • 42
d.f
  • 251
  • 3
  • 2
1

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

(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

Sergey
  • 17,423
  • 13
  • 38
  • 64
1

For zsh users:

$ git stash apply stash@'{'1'}'
user3251328
  • 168
  • 1
  • 8
1

Simply put stash id between simple quotes:

git stash apply 'stash@{1}'
Adriano
  • 467
  • 4
  • 8
  • 3
    How does this answer the question? There is no #3 index in stash list. If this is a serious answer please explain why this command will solve the problem – Brad Mar 08 '17 at 19:59
  • I edited my answer for clarity: the main idea was to simply puts stash id between simple quotes. It applies to 'apply' or 'drop' subcommands. The stash id number does not actually matter – Adriano Mar 09 '17 at 15:19
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – DimaSan Mar 09 '17 at 22:51