Search code examples
gitgit-rebasegit-stashgit-checkout

git rebase: weird stash behaviour


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.


Solution

  • 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}
    

    View the stash content

    # 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>
    

    enter image description here