[Git] Git Stash
Git Stash
- Needs for Stash
- Git Stash & Pop
- Multiple Stashes
- Dropping & Clearing Stashes
Needs for Stash
- When wanting to switch to another branch when there is an uncommitted changes on the current branch: two possibilities
- conflict exists: changes come to the switched branch
- conflict unexists: Git will tell to commit or stash
- Stash can be used to switch over to another branch while not commiting(but saving the changes of) the changed files
Git Stash & Pop
- Git stash: Take all uncommitted chnages(unstaged & staged) and stash them, reverting the changes in a working copy
- Git pop: Take the changes that were in the stash, pop them off and add them to the working directory/staging area
# stash
git stash
git stash save # same as above
# do whatever needed like git switch and commit etc.
# pop
git stash pop
Git Stash Apply
- Apply whatever is stashed without removing it from the stash
- Useful when wanting to apply the stashed changes to multiple branches
- Conflicts can occur which needs to be solved
# apply
git stash apply
Multiple Stashes
- Stashes will stack when stashing multiple times
# view stash list
git stash list
# apply specific stash git stash apply stash@{number}
git stash apply stash@{2}
Dropping & Clearing Stashes
# drop specific stash git stash drop stash@{stash_id}
git stash drop stash@{2}
# clear all stashes
git stash clear