How do I add further changes to a stash in Git

Casebash picture Casebash · Nov 9, 2011 · Viewed 10.1k times · Source

Suppose that I have stashed some changes and I want to add further changes into the same stash (such as stash@{0}). Is there an easy way to do this? What about combining two stashes into a single one?

Answer

VonC picture VonC · Nov 9, 2011

I don't see any "git stash" option allowing to modify an existing git stash.

A possible way to achieve this would be:

  • stash your additional changes (stash@{1})
  • stash everything else (stash@{2})
  • create a tmp branch from the commit (HEAD) your are currently modifying
  • git stash pop twice
  • git stash, creating a new stash@{1} with both content in it,
  • deleting your temporary branch and checkouting the initial branch you where in
  • git stash pop once (to restore all the pending changes)
  • continue your selective stash

Five years later, Powerslave proposes in the comments:

The branching magic is completely unnecessary.
You could simply

  1. Create a new stash with whatever you have.
  2. git stash apply both changesets (you can git stash pop instead, but in that case you're in trouble if you accidentally screw up).
  3. Create a new stash with these merged changes.
  4. git stash drop the other two changesets if you used apply instead of pop