SAGARFIVE

1. Introduction

2. Git Basics

3.  Git Terminology

4.  Git Branching

5.  Git - Github

6.  Git Add (Git staging)

7.  Git Commit

8.  Github Advanced

9.  Git Remote

6.5 Git stash

  • 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

git stash commands :

1To stash(hide) the staged filesgit stash
2To stash(hide) staged/untracked filegit stash -u
3To Git Stash Save (Saving Stashes with the message)git stash save “<Stashing Message>”  
4To see list of stashesgit stash list
5To get back to stashed filegit stash pop
6To bring the older stash outgit stash pop stash@{stash-number}
7To drop last stashgit stash drop
8Stashed some work on a particular branch and continued working on that branch.git stash branch <Branch Name>  
9Deleting all the available stashes at oncegit 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

(iii) To see list of stash:

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}