Mihkel L.
Mihkel L.

Reputation: 1573

Git stashing confusion

The problem is that stashed changes won't stay in the branched i stashed them. And other branches stashes will be overwritten Example:

I do:

    git checkout iss4
// made some changes
    git stash

and it says:

Saved working directory and index state WIP on iss4: 9dd2345 /.../

then i do:

git checkout master

and when now i do git stash show, it suddenly can still see my stashed changes. So this makes it so, that it overrides all my other stashes on other branches. Yes, when i realized this, i already had, lost about a week of work :/(EDIT: Comes out i didn't lose it, had it all in my stashes list =) )

And my question is how to make it so that i can work on several branches at once.

Upvotes: 2

Views: 253

Answers (2)

Hidden
Hidden

Reputation: 7482

A stash is a single place for temporarily storing information and it has no real notion of storing branch specific information.

You mentioned that you had lost a weeks worth of work. I would recommend using stashes as the exception. For the most part, you should rely on committing frequently to local branches instead. This way you will have commit messages and history and you will also be able to merge and cherry-pick code that you want into other branches.

That's one of the powerful features of using a Distributed Version Control System.

Upvotes: 0

poke
poke

Reputation: 387785

Stashes are not branch specific; while they remember which HEAD they were applied on (as their parent), they exist “globally” in the repository.

More importantly though, stashes are not restricted to just a single one. If you just do git stash, chances are you have accumulated a larger number of stashes. You can see all stashes using git stash list. If you want to apply a specific stash to your current working directory, you can just do git stash apply stash@{N} then.

Upvotes: 6

Related Questions