Tuesday, 12 November 2013

How to pop a git stash that was not the last stashed

Doing

git stash pop

pops the last changes that were stashed.

However, if you want to pop a git stash that was not the last one stashed, you need to use

git stash pop stash@{n}

For example, when following are the stashes (given by git stash list):

stash@{0}: On master: Uncommitted changes before update operation at 04/09/13 9:02 AM
stash@{1}: On refactor: Checkout migration at 09/07/13 1:20 PM
stash@{2}: On refactor: Checkout migration at 09/07/13 8:54 AM
stash@{3}: On master: Checkout refactor at 08/07/13 11:00 PM
stash@{4}: On refactor: Checkout master at 08/07/13 10:59 PM
stash@{5}: On master: Checkout bug-456231 at 05/07/13 9:37 AM

stash@{6}: WIP on master: 154bb0f Merge branch 'refactor4'

the following command pops and applies stash@{3}:

git stash pop stash@{3}

No comments :