📜  git stash back - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:30:56.588000             🧑  作者: Mango

Git Stash Back - Shell/Bash

Git stash back is a very useful command that allows you to retrieve previously stashed changes. It is especially handy when you have a lot of changes that you don't want to commit right away, but you also don't want to lose them. In this guide, we will cover how to use git stash back in the Shell/Bash environment.

Stash Changes

Before we can use git stash back, we need to stash our changes. To do this, we use the git stash command, like so:

$ git stash

This will save your changes to the stash and revert your working directory to the last commit in your branch.

List Stashes

To see a list of stashes, use the following command:

$ git stash list

This will list all stashes in reverse chronological order, with the most recent one at the top.

Apply Stash

Now that we have stashed our changes and can see them in the list, we can apply the stash with the following command:

$ git stash apply <stash@{n}>

Replace n with the number of the stash you want to apply. If you omit the n parameter, Git will apply the most recent stash by default.

Drop Stash

Once you have applied the stash, you can drop it with the following command:

$ git stash drop <stash@{n}>

Replace n with the stash you want to drop. If you omit the n parameter, Git will drop the most recent stash by default.

Conclusion

Git stash back is a very useful command that allows you to retrieve previously stashed changes. It can be a lifesaver when you have a lot of changes that you don't want to commit right away, but you also don't want to lose them. Use git stash, git stash apply, and git stash drop to make your life easier and more productive.