GIT stash

From Origami_Wiki
Jump to navigation Jump to search

Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

An example of the stashing is shown below.

    • Made a change in a file.
    • git stash save "message about change"
    • git stash list (lists stashes)

Example:
stash@{0}: msg1
stash@{1}:msg2

After stashed, you can now switch branches, work on other things etc.
When ready, you can take the stash back, by using the below bethods.

(a) git stash apply stash@{0}
(got the changes back)
git stash list (see the stash is still there, not deleted)

(b) git stash pop
This takes the stash on top of list and applies it, then delete the stash.
Note:
Multiple stashes can be added as needed.
To simply delete a stash:
git stash drop stash@{0}
git stash clear

Note: stashes can be carried over to other branches too.
For this,
You can do one stash at (say) master branch, and then do a 'git stash pop' at any other branch (say development).