GIT stash options – name, save, list, pop, show, clear, drop
The stash command is to save all local changes and move to the clean copy. This tutorial will discuss all possible options with the git status. Each option provides functionality to manage changes.
GIT stash name:
While saving changes via git stash, we can use the git stash name to give a meaningful full name to a stash. The name is optional. But when there are multiple git stashes, and later we want to apply specific changes, giving a meaningful full name to a stash is useful.
GIT stash save:
The git stash command saves the working changes. The save is implicit while issuing the git stash command without a name. When you need to give a name to a stash, the git stash save command needs to use along with a message.
E.g., git stash save “Git stash message.”
GIT stash list:
The git stash list shows all the stashes done till now. The second pop will not apply until the changes from the first pop are not committed.
#git stash list
stash@{0}: On Master: Messgage1
stash@{1}: On Master: Message2
GIT stash apply:
The option applies a git stash to the working copy. At a time, we can apply only one stash. If you need to apply another stash, do a hard reset or commit the changes.
#git stash apply stash@{1}
GIT stash pop :
The git stash pop applies the last stash and deletes it from the list. Useful when you need to apply all stashes one by one. The git stash pop is similar to the POP from the queue data structures. Where n the latest inserted element is getting from the queue on POP and removed after the POP. If the git can not merge files and there are conflicts, the pop does not remove the stash from the list.
#git stash pop
#git stash list
stash@{0}: On Master: Messgage1
GIT stash show:
The git stash show displays the changes done for a stash.
GIT stash clear:
The git stash clear removes all stashes. Please make sure that you do not need any of the stashes before using git stash clear.
GIT stash drop:
A git stash drop, you can drop a stash when there are conflicts with the git stash pop. The stash is not removed from the list. In this case, you must merge manually and remove the stash with the git stash drop command.