First, let's look up the document of git checkout
.
git checkout [-p|--patch] [] [--] ...
When <paths>
or --patch are given, git checkout does not switch branches. It updates the named paths in the working tree from the index file or from a named <tree-ish>
(most often a commit). In this case, the -b and --track options are meaningless and giving either of them results in an error. The <tree-ish>
argument can be used to specify a specific tree-ish (i.e. commit, tag or tree) to update the index for the given paths before updating the working tree.
git checkout with <paths>
or --patch is used to restore modified or deleted paths to their original contents from the index or replace paths with the contents from a named <tree-ish>
(most often a commit-ish).
As we can see, the args after -p
should be a specific tree-ish (i.e. commit, tag or tree), and you passed stash
. So, how would git handle stash
is the key point.
You can try git checkout stash
to see which commit git will goto, and this is what you actually checkout -p
.
At last, I think you can just use git stash apply
to make it work.