git

Notes on git stash

Occasionally you may have several changes on your working directory and need to change branch in a clean state.

In this case, the best approach is using git stash which allow to stash away your changes and get them back later.

Definitions

Stash
Whole list of stash entry
Stash entry
Single entry created when `git stash` or `git stash push`.

This is the dirty working directory away you stashed away.

Basic commands

git stash push   # create a stash entry
git stash push -m "my changes" # create a stash entry with message

git stash pop    # apply and remove from stash entry from stash
git stash apply  # apply stash entry changes only

pop get the files from the stash entry and then delete the change from the stash. Thus if you try to re-apply the same stash entry it won’t work.

apply get the files from the stash entry. You can apply infinite times.

Manage the stash

git stash list              # list all stash entry

git stash show stash@{0}    # show files in stash entry
git stash show -p stash@{0} # show diff in stash entry

git stash drop stash@{0}    # detele stash entry