Monday, 28 February 2022

Git Stash Save Changes Temporarily

Git Stash sample workflow

1. Modify a file

2. Stage file

3. Stash it

4. View stash list

5. Confirm no pending changes through status

6. Apply with pop

7. View list to confirm changes

# Modify file and add a file

git add .

git stash save "Saving changes"

git stash list

git status

git stash pop

git stash list

git status


#update the branch files if necessary

#make staging area clean and commit changes

git status

git add -A

#add a newfile

git status

git stash

Saved working directory and index state WIP on new_branch: e436353 updated main

git status

On branch stash_branch

nothing to commit, working tree clean

git stash list

stash@{0}: WIP on new_branch: e436353 updated main

#can do many stash, the stash will hide the files

git stash 

git stash show

#can create a new branch

git stash branch stash_branch stash@{0}


git stash drop stash@{1}

#drop only  latest

git stash drop -q

#recover step by step

git stash pop stash@{0}

git stash apply stash@{0}

git stash apply 

#recover all changes, good to use if not too many stashes available

#recover not specifying stash number


#show untracked files

git clean -n

#remove  all untracked files

git clean -f

#date range, git stash list –before and –after options

git stash list --before 5.days.ago

#summary of changes for each element

git stash list --stat

#diff of changes for each stash

git stash list -p

#difference between a stash and your local Git working tree

git stash show -p stash@

# difference between stash and HEAD on the main branch

git diff stash@ main

#-p option (patch) to view the full diff of a stash

git stash show -p

#add a description to the stash

git stash save <description>

#push the stash entry created via git stash create to the stash reflog

git stash create "sample stash"


git stash store -m "sample stash testing.." "63a711cd3c7f8047662007490723e26ae9d4acf9"

git stash list

stash @{0}: sample stash testing..

No comments:

Post a Comment