Pratik Patel
Pratik Patel

Reputation: 2443

Git: How to store 'git stash' Data

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?

Upvotes: 2

Views: 714

Answers (3)

yorammi
yorammi

Reputation: 6458

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>

Upvotes: 1

Gupta
Gupta

Reputation: 10358

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

Upvotes: 1

David Ferenczy Rogožan
David Ferenczy Rogožan

Reputation: 25381

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.

Upvotes: 2

Related Questions