📅  最后修改于: 2023-12-03 15:15:18.650000             🧑  作者: Mango
Git is a powerful version control system used by millions of developers around the world. One of the many useful features of Git is the ability to stash changes that are not yet ready to be committed. In this article, we will explore how to use the 'git stash' command in the Shell/Bash environment.
Git stash is a command that allows you to temporarily save changes that are not yet ready to be committed. This is useful when you are in the middle of working on a feature and need to switch to another branch, but do not want to commit your changes just yet.
To use Git stash, first ensure that you are in the root directory of your Git repository. Then, open your terminal or command prompt and type the following command:
$ git stash save "your message here"
This will save your changes to a temporary storage location called the stash, along with the message you provided in quotes. You can then switch to another branch or perform any other Git operation that requires you to be in a clean state. When you are ready to return to your original branch and retrieve your changes, use the following command:
$ git stash apply
This will apply your most recent stash to your working directory. If you have multiple stashes, you can specify which one to apply by using the following command:
$ git stash apply stash@{num}
Replace 'num' with the number of the stash you wish to apply, starting from 0 for the most recent stash.
Displays a list of all stashed changes.
$ git stash list
Displays the changes in the most recent stash.
$ git stash show
Deletes the most recent stash.
$ git stash drop
Applies the most recent stash and then deletes it.
$ git stash pop
Git stash is a useful and powerful command that allows you to save changes temporarily and switch between branches. With these basic commands, you can start utilizing Git stash in your workflow and improve your version control practices.