Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
In Git, a stash is a way to save changes that are not yet ready to be committed. Stashes are useful when you need to switch to a different branch or work on a different task, but you don't want to commit your changes yet. However, sometimes you may need to delete a stash that is no longer needed. In this lab, you will learn how to delete a specific stash in Git.
Delete a Git Stash
You have a Git repository named https://github.com/labex-labs/git-playground. You have created a stash using the command git stash save "my stash". Now, you want to delete this stash because you no longer need it.
- Change to the repository directory using the command
cd git-playground. - List all stashes using the command
git stash list. You should see the stash you just created. - Delete the stash using the command
git stash drop stash@{0}. - List all stashes again using the command
git stash list.
The stash you just deleted should no longer be there.
Summary
To delete a specific stash in Git, you can use the command git stash drop <stash>, where <stash> is the name of the stash you want to delete. In this lab, you learned how to delete a stash in Git using a specific example.