- Run
source setup.sh
(or.\setup.ps1
in PowerShell)
You are working on your project. You've staged some work and have some unstaged work as well. Suddenly, you're made aware that a bug has made it to production. You'll stash your work, fix the bug and get back to your original work.
- Explore the repo
- What work do you have in the working directory?
- What work do you have staged ?
- What does the commit log look like ?
Notice that file.txt has some staged changes (i.e. changes in the index) and unstaged changes (changes in the working directory)
- Use
git stash
to stash your current work.- Now, what work do you have in the working directory?
- What work do you have staged ?
- What does the commit log look like ?
- What does the stash list look like ?
- Fix the typos in bug.txt on master and commit your changes.
- Now to get back to your work, apply the stash to master.
- What work do you have in the working directory?
- What work do you have staged ?
Oops. All our changes are unstaged now. This may be undesirable and unexpected
- Undo our changes with
git reset --hard HEAD
. This is an unsafe command as it will remove files from your index and working directory permanently, but we have our changes safely stashed so we're ok. Review the reset kata if you're unsure of what happens here. - Apply the stash to master with the
--index
option.- What work do you have in the working directory?
- What work do you have staged ?
Ok, back to where we were!
- We won't need the stash anymore. Drop it.
- What does the stash list look like ?
- What does the commit log look like ?
git status
git status -s
git diff
git diff master
git stash
git stash list
git stash apply
git stash apply --index
git stash drop
git log --oneline --all --graph
git commit
git add