0

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.

pageman
  • 2,864
  • 1
  • 29
  • 38
PlayHardGoPro
  • 2,791
  • 10
  • 51
  • 90
  • 2
    There is not enough information here for us to answer your question. Pulling origin/master into master and then merging master into myFeature will generally not undo the changes in myFeature, but there are many situations that would deviate from normal assumptions and might look like you describe. Bottom line, though, if you want us to trouble-shoot this you need to provide enough info to reproduce the problem, and when I do steps like you describe I don't get the behavior your describe. – Mark Adelsberger Mar 21 '18 at 13:02
  • 1
    You did not commit yet? What did you not commit? If the merge was done cleanly, it should auto-commit, you shouldn't have files *from the merge* in uncommitted status, unless you explicitly asked git to merge without committing, or if there was a merge conflict or other error. Did you have uncommitted work *before* you merged? You need to be more explicit about what the state was of your repository and what kind of changes you "lost". – Lasse V. Karlsen Mar 21 '18 at 15:02

1 Answers1

1

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.

antzshrek
  • 9,276
  • 5
  • 26
  • 43