List All Stashes

GitGitBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

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.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL git(("`Git`")) -.-> git/DataManagementGroup(["`Data Management`"]) git/DataManagementGroup -.-> git/stash("`Save Changes Temporarily`") subgraph Lab Skills git/stash -.-> lab-12738{{"`List All Stashes`"}} end

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?

  1. Navigate to the git-playground directory:
cd git-playground
  1. Create a new file named test.txt and add some content to it:
echo "hello,world" > test.txt
git add .
  1. Use the following command to stash your changes:
git stash save "Added test.txt"
  1. Create another new file named test2.txt and add some content to it:
echo "hello,labex" > test2.txt
git add .
  1. Use the following command to stash your changes:
git stash save "Added test2.txt"
  1. 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.

Other Git Tutorials you may like