You were in the middle of heroic code changes and then a bug report arrived like a gremlin. Instead of committing half baked work or starting a ritual sacrifice you can stash your changes. The git stash stack is a temporary parking lot for uncommitted edits that keeps your working tree clean while you do other things on the command line.
Here is the pragmatic loop most developers use when they need to pause one task and start another. It keeps your version control tidy and your future self less annoyed.
If you want to save uncommitted changes run this. The working directory will reset to the last commit so you can change context without trashing your progress.
git stash push -m 'feature X work in progress'
# or the shorthand
git stash
Checkout the branch you need and do the work that cannot wait. The stash stays on the stack until you bring it back.
When you want your changes back use git stash pop
. This applies the latest stash and removes it from the stack, which is usually what you want unless you like collecting digital clutter.
git stash pop
# to apply a specific entry use the index from git stash list
git stash pop stash@{n}
Sometimes the stash does not drop because a conflict happened. Treat this like any other merge conflict. Edit the files, mark them as resolved and commit the result.
# resolve conflicts in your editor
git add path/to/conflicted.file
git commit -m 'resolve stash conflict'
If the stash failed to drop and you are sure you no longer need it run git stash drop stash@{n}
to remove the stale entry.
Want to see what you have stashed before applying anything use:
git stash list
git stash show -p stash@{n}
When the stack becomes a nostalgia shelf of useless snapshots clean it with:
git stash clear
git stash push -m 'short context'
so you do not need to guess what stash@{3} was.git stash apply stash@{n}
which does not remove the stash entry.That covers the full loop from saving changes to applying them and resolving merge conflicts. The commands above will keep your developer workflow sane and your git history tidy. If you follow these steps you will be able to juggle bugs and experiments without losing your work or your dignity.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.