stash@{1} is ambiguous?

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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).

Solution 2 - Git

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.

Solution 3 - Git

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

Solution 4 - Git

For zsh users:

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

Solution 5 - Git

Simply put stash id between simple quotes:

git stash apply 'stash@{1}'

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUncommonView Question on Stackoverflow
Solution 1 - GitJan HudecView Answer on Stackoverflow
Solution 2 - Gitd.fView Answer on Stackoverflow
Solution 3 - GitSergeyView Answer on Stackoverflow
Solution 4 - Gituser3251328View Answer on Stackoverflow
Solution 5 - GitAdrianoView Answer on Stackoverflow