2

I had some particular uncommitted changes in my development branch and I stashed them using git stash command, and I am re applying those stashed changes using git pop command.

But this specific state I want to preserve (If possible then may me in some text format).

Because there are many times I have some uncommitted changes which are not particular I am doing that just sake for branch changing activity so my particular stashed changes get overlapped(removed). So I want to preserve that particular stash.

Is there any chance I can preserve the specific stashed changes in some file if possible?

1
  • 2
    did you tried to create another branch and save them? Commented Mar 22, 2016 at 12:47

3 Answers 3

2

Use apply instead of pop:

git stash apply

You can also apply some specific stash (not the most recent one). Following command will apply the second most recent stash (index starts at 0, which is the most recent stash):

git stash apply stash@{1}

The same also works with pop.

pop is, in fact, equivalent of these two commands:

git stash apply
git stash drop

Check the git-stash documentation for details.

Sign up to request clarification or add additional context in comments.

Comments

1

Because there are many times I have some uncommitted changes which are not particular I am doing that just sake for branch changing activity so my particular stashed changes get overlapped(removed). So I want to preserve that particular stash.

You can have Multiple stashes

git stash list

stash@{0}: WIP on master: 686b55d Add wolves.
stash@{1}: WIP on gerbils: b2bdead Add dogs.
stash@{2}: WIP on gerbils: b2bdead Add dogs.

Stash names are shown in the list. And gives you the list of stashs which are saved in stash's stack.

$ git stash apply stash@{1}
# On branch gerbils
# Changes not staged for commit:
#
# modified: index.html

stash@{0} is the default when applying; specify the stash name to apply a different one

git stash apply <stash-name>

Hope this help you !!!

1 Comment

Thanks , It is helpful.
1

If you want to save the stash into a file, run:

git stash show -p stash@{1} > <file-path>

And if you want to apply it back, run:

git stash apply < <file-path>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.