GIT stash options – name, save, list, pop, show, clear, drop

The stash command is to save all changes from a clean copy.  In this tutorial, we 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 git stash name to give a meaning full name to a stash.  The name is optional. But when there are multiple git stash and layer we want to get back specific changes then giving a meaning full name to a stash is useful.

GIT stash save: 

The git stash command saves the working changes.  The save is implicit while issue git stash command without a name. When need to give a name to a stash, the git stash save command, the need to use along with a message.

Eg. 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 
[email protected]{0}: On Master: Messgage1
[email protected]{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 either do a hard reset or commit the changes.

#git stash apply [email protected]{1}

GIT stash pop :

The git stash pop is applying the last stash and delete from the list. Useful when you need to apply all stashes one by one. The git stash pop is similar to the POP form 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 is/are conflicts, the pop does not remove the stash from the lits.

#git stash pop

#git stash list 
[email protected]{0}: On Master: Messgage1

GIT stash show:

Git stash show, display 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 lits. In this case, you need to merge manually and remove the stash with the git stash drop command.

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top