DEV Community

jeffrainey
jeffrainey

Posted on

Git Stash, Retrieving Items That Are Not the Most Recent

Some Git commands like stash show are used regularly but not enough to keep top of mind. These are some commands I often find myself Googling for. If you are new to Git, checkout this post, Git 101 for the basics.

What is Stash?

Stashing work is a great way to set things aside for a moment. For example, I am working on a feature but a customer support request comes in that I want to see locally. No problem.

git stash

Now I can safely switch to master and see what is going on. When I am ready to jump back to my work:

git stash apply

OR

git stash pop

I typically use the first one since the last not only gives me the last stash item, but also removes it from the stash history.

What if I want an older stash, not the most recent one?

This comes up for me occasionally and is one I find myself Googling for specific options. In this case:

git stash list

This brings up a nice list of your previous stashes if you haven't been popping them. They will look something like this:

  • stash@{0}: WIP on branch-name: (last commit hash and message here)
  • stash@{1}: WIP on branch-name: (last commit hash and message here)
  • etc.

This is fairly helpful but it doesn't really show what files I was working on...

Read On

Top comments (0)