Git stash

git-stash is used to record the current state of the working directory and the index and want to clean the directory with the intent of applying or dropping the stashed changes to the working directory. Suppose there are changes made to a file in working directory but before committing those changes you are willing to pull the changes from master. Stash the changes made to working directory-

git-branch-9

Stash Changes

 git stash

You may also stash changes with comments-

git stash save "Content updated to stash"

git-branch-10

You can stash multiple times, while stashed git reference this with unique name i.e. stash@{0}, stash@{1} and so forth. You may also switch between the branches once stashed as the recorded copy is available between the branches.

If you want to see the stash list

 git stash list

git-branch-11

Revert Stashed Changes
To apply stashed changes made to the working directory, use either-

 git stash pop

This shall apply/merge changes to the working directory and remove it from stash list.

 git stash apply

This shall apply/merge changes to the working directory but still keep the copy of stash.

Removing stashed changes
To delete specific stash item use-

 git stash drop stash@{0}

To delete all stash items-

 git stash clear

Use Stash clear wisely as it is destructive.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s