Reputation: 996
I did a git rebase -i
, selected one commit for edit and git stopped at that commit.
I now try to checkout one patch from the stash with git checkout -p stash
.
But this gives me weird old stash contents while git stash show -p
gives me the expected patches from which I want to checkout one.
What happens here and how can I checkout my hunk from the stash?
Let me know if I shall provide more info.
Upvotes: 0
Views: 85
Reputation: 142094
Why not work directly with stash without the checkout
command?
git stash pop
Remove a single stashed state from the stash list and apply it on top of the current working tree stat
git stash apply
Like pop, but do not remove the state from the stash list
git stash show
Show the changes recorded in the stash as a diff between the stashed state and its original parent
In your case you will need to use the stash@{<revision>}
to execute any stash action you wish to perform.
For example:
git stash show -p stash@{0}
# display on the stash content
git stash show stash@{1} -u
# checkout the desired commit and choose the right action you want
git checkout -p stash@{0} -p <path to file>
Upvotes: 1
Reputation: 8524
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.
Upvotes: 0