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. It allows you to temporarily save your work and switch to another branch or commit without losing any changes. When you're ready to continue working on your changes, you can apply the stash to your working directory. In this lab, you will learn how to apply the latest stash to your Git repository.
Apply the Latest Stash
You are working on a project in your Git repository and have made some changes that are not yet ready to be committed. However, you need to switch to another branch or commit to work on a different feature. You don't want to lose your changes, so you decide to stash them. Later, when you're ready to continue working on your changes, you need to apply the latest stash to your working directory.
To apply the latest stash to your Git repository, follow these steps:
- Clone the Git repository named
https://github.com/labex-labs/git-playgroundto your local machine. - Navigate to the
git-playgrounddirectory. - Make some changes to the
README.mdfile, e.g. write "This is a new line" in theREADME.mdfile. - Run the command
git stashto stash your changes. - Run the command
git stash listto see a list of your stashes. You should see one stash in the list. - Run the command
git stash applyto apply the latest stash to your working directory. - Check the
README.mdfile to see that your changes have been applied.
git clone https://github.com/labex-labs/git-playground.git
cd git-playground
echo "This is a new line" >> README.md
git stash
git stash list
git stash apply
cat README.md
This is the result of running cat README.md:
## git-playground
Git Playground
This is a new line
Summary
In this lab, you learned how to apply the latest stash to your Git repository. Stashing your changes allows you to temporarily save your work and switch to another branch or commit without losing any changes. Applying the latest stash allows you to continue working on your changes when you're ready.