I was working on master, finished up what I needed to do, then did
git commit -am "message".
I wanted to test out writing a new feature, so I did:
git branch NewFeature
followed by
git checkout NewFeature
I then made changes to version controlled files, came back to git and did
git checkout master
What I forgot to do was commit those changes to the NewFeature branch. My fault, yes, but looking around on SO it seems like that should have failed without the -f flag. Unfortunately, it just merged my changes with master. Naturally I freaked out and did
git reset --hard head
It seems like I lost all the work I had done on the NewFeature branch when I switched back as well! What did I do wrong?
This is normal behavior.
If you don't have conflicting changes between branches, git simply "moves" the changes over when you checkout. Git should show you a summary of the moved files after the checkout.
Doing git reset --hard HEAD will have reverted your changes.
If you have uncommitted changes but you want to work on other things in a different branch, you can stash your changes for later. See stash docs.
git stashgit checkout <branch>git checkout <oldBranch>git stash pop to un-stashIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With