0

I've merged my branch (let's call it branch1) to master successfully. A day after someone merged another branch (branch2) without pulling before (I think that what happened) and now all of the changes in branch1 have been dismissed.

Since the branch is still open I tried to merge the branch into master but it says "Already up-to-date".

I don't want to reset master back to branch1 merge because it will dismiss all of branch2 changes.

Any ideas?

Yuval
  • 764
  • 1
  • 9
  • 23
  • The other person must of `git push --force`, tell them not to do this. – Liam Feb 27 '18 at 13:11
  • Well how do I fix it? – Yuval Feb 27 '18 at 13:12
  • your easiest solution will be to create a new branch on your local. Delete the original (locally) `pull`, then merge your new branch into the original branch from the server, then `push` this – Liam Feb 27 '18 at 13:13
  • 2
    @Yuval - Liam is only guessing at your situation. I would not follow his (or anyone's) advice given on the basis of guesswork, because if hidden assumptions about your current state are wrong then you may just get an even bigger mess. If you want the community to solve the problem, the community would need to examine the repo. A better idea (especially since I'm assuming you can't just post the repo publicly) is to ask the right questions ("how do I fix it" is not one of them) to build your understanding until you *know* how to fix it. That said... – Mark Adelsberger Feb 27 '18 at 13:59
  • 2
    @Yuval - ... what we DO know is that something happened other than what you're guessing. We know that because merging without pulling does not overwrite what's already in the branch history (does not "dismiss" the earlier changes, as you put it). That's why Liam is assuming a force push; he's building on your assumption of a merge without pull, and trying to see how that could result in branch1 being undone. – Mark Adelsberger Feb 27 '18 at 14:01
  • 2
    @Yuval - The problem with the assumption of a force push is, it would probably have other symptoms when you (or other colleagues) next tried to pull. But the point is, we just don't know. And trying to reconstruct the history of "how did we get here" is usually simply too hard to do. So instead the best bet is to figure out more about the current state. The `log` and `reflog` commands re your best friend here, to figure out what is, and what was, in the history of each branch, and then work from there. – Mark Adelsberger Feb 27 '18 at 14:04

1 Answers1

0

Since your merge has been lost, you can re-merge your branch1 back to the "new" master

You should still have your existing history of branch1 on your local machine. Look at the history, checkout a new branch at the commit right before it got merged to master.
git checkout -b branch1_redo abcd123

Now do the merge again.

Ben
  • 1,287
  • 15
  • 24