On 10/23/12 12:56, Kayatta Schmidt wrote:
> 1. I have checked out a branch, let's call it "*branchA*" and made some 
> changes.
> 2. The QA team comes back with some priority 1 bug fixes and so I must 
> quickly stash my changes and switch over to "*branchB*."  Let's assume I 
> use the following commands to do this (just for clarity sake):
>> $ git stash save
>> $ git checkout *branchB*
> 3. I finish all of my patching / bug fixes and commit those changes, but I 
> have not yet checked out *branchA *yet...
> This is where I get confused.  My intuition tells me there is no reason to 
> stash pop until I've checked out *branchA *again, but there seems to be 
> very little clarification on how the pop affects the branches I am 
> currently working on...  *So *my question is - when I pop and/or apply the 
> stashed changes - since I'm still in *branchB *will it mess up any of the 
> code in *branchB*?  If yes - why?  If not - would I need to do another git 
> add/commit before it does?

Unless you commit it, it won't affect your repository (other than,
of course, removing the stashed item if you pop).  It might mess up
your working copy, but you can re-stash the changes.

You say "there is no reason to stash pop until I've checked out
*branchA* again"...if that's where you want to apply the changes,
then yes.  However, I find it intuitive if I'm working on the wrong
branch to stash my changes, checkout the other branch where they
belong, then stash-pop them.

> Basically - my understanding, which is more of an assumption at this point, 
> is that to get those stashed code changes back into the branch I want I 
> would need to (again in chronological order):
> $ git checkout *branchA*
> $ git stash pop
> ... finalize changes/do some coding...
> $ git add changedfiles
> $ git commit
> Is this correct?

If you've accidentally popped the stash in the wrong branch, just
re-stash it, switch to the right branch, and pop it again:

  (branchA)$ git stash save "Stupid QA emergency [#3141592]"
  (branchA)$ git co -b branchB
  (branchB)$ # ... hack, hack, hack ...
  (branchB)$ git commit -am "Solved the problems of the universe"
  (branchB)$ git stash pop
  (branchB)$ # ... doh!  wrong branch!
  (branchB)$ git stash save "Moving changes back to branchA"
  (branchB)$ git checkout branchA
  (branchA)$ git stash pop
  (branchA)$ # ... optional hack, hack, hack ...
  (branchA)$ git commit -am "Put my WIP on the right branch"

The only difficulties that come to mind:

1) you stash-apply rather than stash-pop (I almost always use pop),
in which case you'd have to git-reset branchB (or stash them and
delete the stash) to abandon the changes, then switch back branchA
and pop/apply them.

2) if you had uncommitted work in branchB and apply'ed/pop'ed atop
those changes:  the re-stash would stash those changes too.  You
might be able to work around this since stash understands a "-p"
argument to select hunks to stash (one of my recently-discovered
features that I *love*)


You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To post to this group, send email to git-users@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to