Reputation: 2942
I have no idea why, but today I did this:
git checkout master
git pull origin master
git checkout myFeature
git merge master
I was merging master
with myFeature
branch so I could solve any conflicts.
To my surprise, no conflicts were shown and it overwrote my files and I lost everything I did on that new feature.
question 1: Why did this happen? Conflicts
weren't supposed to be shown?
question 2: How to revert it properly? I did NOT commit yet.
If I do a git log
it shows all my commits that works (remember, I did NOT commit this merge
yet). I'm not 100% sure if I should reset --hard
to the last commit SHA1. I do not want to keep current changes (which is the merge
) but I'd like to keep everything BEFORE the merge
, which was the last commit.
Upvotes: 0
Views: 1134
Reputation: 9963
question 1: Why did this happen? Conflicts wasn't supposed to be shown?
This happened because you were suppose to merge
from your master and not from your branch. i.e
git checkout master
you should ensure that you're on the master branch, then you run the merge
git merge myFeature
question 2: How to revert it properly? I did NOT committed yet.
To revert your last marge
, run:
git reset head~ <path>
This answer from SO might be of help too.
Upvotes: 1