If you ever used git stash and then thought everything would be fine, welcome to the club. When a stash clashes with the current branch you can either quietly cry or handle it like a developer who knows what they are doing. This short guide shows how to inspect a stash safely apply a stash and resolve merge conflicts without losing your saved work.
Start by looking at what you actually saved. That avoids surprises and the classic regret move where you lose work because you popped the wrong stash.
git stash list
To peek at the top stash patch use this
git stash show -p stash@{0}
This shows the diffs so you can decide if that stash belongs in a museum or should be reapplied to your working tree.
If you want to be cautious use apply because it keeps the stash entry around. Use pop only when you are confident nothing will go wrong.
git stash apply stash@{0}
If that command succeeds you get the saved changes back and the stash still exists. If it fails you will see conflict markers in files and git status will list unmerged paths.
Expect conflict markers inside files. They look obvious and ugly. Open each conflicted file and choose what to keep.
<<<<<<< HEAD
current branch code
=======
stashed changes
>>>>>>> stash
git status
git add path/to/file
When all conflicts are staged create a commit that documents the fix. Keep the message short and human readable.
git commit -m "Resolve stash conflict"
If you used git stash apply and the stash content is no longer needed drop it. If you used git stash pop the stash is usually gone already unless the apply failed.
git stash drop stash@{0}
# or when you are truly sure
git stash clear
Follow these steps and you will survive stash apply conflicts without accidentally deleting work. You can be tidy about it or chaotic and apologize later. Either way you will have fewer surprises and more commit messages that explain why things were fixed.
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.