- Stash is used for leaving the unfinished work, in such a way the git cannot access it
- You don’t want to make a commit of half-done work. Git stashing allows you to do so.
- and continue work on some other files, This can be done by git stash.
- Simple way hiding unfinished work from git staged file tracking
1 | To stash(hide) the staged files | git stash |
2 | To stash(hide) staged/untracked file | git stash -u |
3 | To Git Stash Save (Saving Stashes with the message) | git stash save “<Stashing Message>” |
4 | To see list of stashes | git stash list |
5 | To get back to stashed file | git stash pop |
6 | To bring the older stash out | git stash pop stash@{stash-number} |
7 | To drop last stash | git stash drop |
8 | Stashed some work on a particular branch and continued working on that branch. | git stash branch <Branch Name> |
9 | Deleting all the available stashes at once | git stash clear |
(i) To stash(hide) the staged files :
- Creating and committing three files with names one, two and three
- Data added into one, two
- But data adding is incomplete in three
- In this case everytime if run git status , it shows in staging area
- To hide the three file from staging area
- We can stash the staged files
git stash |
Once after running stash command, the staged files will be hiddenAnd git status will shows working tree is cleanThree file also removed from working directoryWe can see the demo in below screenshot |
(ii) To stash staged(tracking) and unstaged(untracked) files:
- To hide staged/unstaged(untracked) files we can use git stash -u command
git stash -u |
- Created four, five files
- Four added to staging/tracking
- Five is not added for staging area/tracking
- Now with the help of stash we can hide both the staged and untracked files
git stash list |
(iv) To unhide the stashed files :
- Shows back the tracked/untracked files on git status
git stash pop |
(v) To unhide the specific stash :
- Shows back the specific tracked/untracked files on git status
git stash pop stash@{<stash number>} |
git stash pop stash@{0} |