Introduction
🧑💻 New to Git or LabEx? We recommend starting with the Quick Start with Git course.
In Git, stashing is a way to temporarily save changes that are not ready to be committed. Stashing allows you to switch branches or work on a different task without losing your current progress. Once you are ready to continue working on the changes, you can apply the stash and continue where you left off. In this lab, you will learn how to list all stashes in a Git repository.
List All Stashes
You are working on a project in a Git repository and have made some changes that are not yet ready to be committed. You decide to stash these changes so that you can work on a different task. Later, you want to see a list of all the stashes you have created so that you can decide which one to apply. How do you list all stashes in a Git repository?
- Navigate to the
git-playgrounddirectory:
cd git-playground
- Create a new file named
test.txtand add some content to it:
echo "hello,world" > test.txt
git add .
- Use the following command to stash your changes:
git stash save "Added test.txt"
- Create another new file named
test2.txtand add some content to it:
echo "hello,labex" > test2.txt
git add .
- Use the following command to stash your changes:
git stash save "Added test2.txt"
- Use the following command to list all stashes:
git stash list
You should see output similar to the following:
stash@{0}: On master: Added test2.txt
stash@{1}: On master: Added test.txt
Summary
In this lab, you learned how to list all stashes in a Git repository using the git stash list command. This command displays a list of all stashes, including the stash reference, the branch where the stash was created, and the stash message. By listing all stashes, you can decide which one to apply and continue working on your changes.