Recovering an Earlier Git Stash

Aman Kumar
2 min readOct 4, 2024

--

Sometimes, when working with Git, you might stash your changes, make further modifications, and then stash again. Later, you realize you need to go back and apply that first stash, but it seems buried under the new ones. This is a common scenario, and it’s easy to feel stuck.

Created using DallE

Here’s how you can deal with it.

The Problem:

You’ve stashed changes twice and want to retrieve the first stash, but `git stash apply` only applies to the most recent one.

The Solution:

Git keeps a stash list where each stash is saved with an index. You can view the list of all stashes by running:

git stash list

This will show something like:

stash@{0}: WIP on branch-name: …
stash@{1}: WIP on branch-name: …

The most recent stash is `stash@{0}`, and the one before it is `stash@{1}` (your first stash in this case).

To apply the first stash without removing it from the list, use:

git stash apply stash@{1}

If you want to apply it and remove it from the list, use:

git stash pop stash@{1}

Final Thoughts:

Stashing is a super helpful tool when working with Git, but things can get confusing when multiple stashes pile up. Thankfully, Git keeps them neatly organized, and it’s easy to retrieve any stash as needed.

If this article was helpful, give it some claps. I’m deeply involved with AI and LLMs. Follow me on Medium for more insights.
Feel free to say hi or connect via Twitter and LinkedIn.

--

--