6

I'm having a heck of a time orchestrating my first major branch and merge. What happened is I have a main branch called 'main', and a new branch that created called 'branch2' off of 'main'. I made a whole lot of changes in 'branch2' in several files over several weeks and created some new files as well. I had also made a few minor changes in 'main' during this time. When time came to merge, I checked out 'main' and called git merge branch2. Not surprisingly, it told me that I had conflicts to resolve in one of my files. So I used git mergetool to open meld, my diff viewer of choice, to resolve the differences. After reconciling those differences, I called git merge branch2 again, and the merge happened successfully.

The problem is that it didn't actually merge successfully. Some elements merged properly, but some changes in 'branch2' never moved over and I have no idea why. I tried calling git merge branch2, but now it just says "everything up to date". This clearly isn't right, because if you git checkout branch2, then you can see changes that aren't in 'main'.

Any idea what might have happened? Why is git declaring "everything up to date" when it didn't merge correctly? Is there any way to force git to try the merge again?

J-bob
  • 8,380
  • 11
  • 52
  • 85
  • Usually after I resolve the conflicts with `git mergetool`, I do a git status to check everything is good. I then compile the source, run tests etc. to make sure everything is fine and then simply commit. Did you do this step? I don't merge again after the conflict resolution but not sure if that has any effect, if any. Also, I usually merge my feature branch in more often. – Luke Hutton Jun 03 '13 at 23:56
  • I would have liked to merge my feature branch in more often, but the purpose of the branch was to keep the new code out of the main code until it's completely ready. I don't want half-baked code in the production version (it's a website, so things in the main branch are seen by the outside world). – J-bob Jun 04 '13 at 00:04
  • It sounds like you made some mistakes when performing the merge, you should probably reset to before the merge commit and merge again. – Micha Wiedenmann Jun 04 '13 at 07:47
  • What happens if you diff between the branches http://stackoverflow.com/a/12913063/717355 ? – Philip Oakley Jun 04 '13 at 12:04
  • calling `diff master..branch2` prints a whole lot of differences. Yet calling `git merge branch2` immediately after returns 'Already up-to-date.` – J-bob Jun 04 '13 at 15:24

1 Answers1

6

You did an evil merge. Run gitk --all to see what’s going on. You went wrong when you called git merge a second time. When you resolved your conflicts, you need to run git commit, not merge.

But git now thinks that your branch2 is merged into main. So you need to remove that merge commit. Use gitk to get the sha fo the last commit before the merge and run git reset --hard **SHA** on the main branch to reset it back to that stage. Then do your merge again.

Chronial
  • 66,706
  • 14
  • 93
  • 99