Posted over 4 years ago. Visible to the public. Repeats.

Git stash: Working with old Entries

First find the reference for the entry you want through looking at the stash:

Copy
$ git stash list stash@{0}: WIP on feature/foo stash@{1}: WIP on feature/bar stash@{2}: WIP on fix/baz

Now you can simply use that reference, but curly braces must be escaped:

Copy
git stash pop stash@\{1\}

or quoted:

Copy
git stash apply "stash@{1}"

Quick reminder to not shoot yourself in the foot:

  • apply applies the entry to the working directory but will not delete it from the stash
  • pop applies and deletes the entry from the stash (only if there were no conflicts when applying it)
  • drop will only delete and not apply the entry

Running these commands without a reference will use it with the last entry.

Partial stash pop

Sometimes you only want to pop parts of the stash. Do this the way vice versa:

Copy
git stash pop git stash -p # Now move all the unnecessary parts back into the stash

Show Diff of the stash

To show the code changes of the last (or any other) stash in patch format, use the following command:

Copy
git stash show -p git stash show -p stash@{1} # to view the second most recent entry in patch form

With tig

tig offers an easy way to browse through the contents of your stash as well: tig stash. Navigating works as expected.

Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Avatar
Judith Roth
Last edit:
5 months ago
by Daniel Straßner
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Judith Roth to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more