1

I was asked by my colleague to assist with following issue:

  • He was working in a branch feature
  • He merged master into feature, which resulted in a huge swath of conflicts
  • He resolved many of the conflicts by "take theirs" or "take mine", often incorrectly.
  • He commited and pushed the merge.
  • He realized what he has done and called for help.

My first instinct was to move the pointer back using branch -f, but that requires push --force, which is disabled on the repo.

Second attempt was git revert -m, which however reverted the merge completely and blocked me from doing again, saying "Already up-to date" (since technically all those commits from master were aready merged in feature).

As an immediate solution, I ended up discarding the branch and making a new, fixed one.

Is there a better way to fix this situation that doesn't require push --force?

Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
  • Could you clarify "blocked me from doing again"? Blocked you from doing what again? I do believe reverting is the correct approach here so I would continue along that path. – jbu Feb 02 '17 at 09:50
  • If he is the only person who works with the branch `feature` than it is better to `reset` and `push -f`. If not I agree with @jbu. – Raz Feb 02 '17 at 10:04
  • @jbu When you attempt to merge after such revert, you get "Already up-to date", because at that point, `master`'s current tip (and all commits leading to it) is already merged into `feature`. It's just that `feature` has locally chosen to discard those changes. – Matěj Zábský Feb 02 '17 at 10:04
  • Another thought is to just soft reset feature back prior to the original commit and then add, commit and push. But regarding the already up to date message, a revert will add a commit so there is absolutely no way the remote would have that unless i am misunderstanding something fundamental about git. – jbu Feb 02 '17 at 10:29
  • "reverted the merge completely and blocked me from doing again" this is known issue, and there are some ideas how to handle it https://stackoverflow.com/q/1078146/2303202 just for example, actually there are a lot of very similar questions. Since non of the fix ideas are ideal forced push is not that bad solution if you can afford it (that is: all your developers are able to rebase after you forcepush) – max630 Feb 02 '17 at 11:25

1 Answers1

0

You could do a

$ git reset --hard @commit

If the merge was the last commit you can replace @commit by HEAD^ otherwise replace by the last commit before the merge one.

This will get you back how you were before the problematic merge.

Carlos Afonso
  • 1,927
  • 1
  • 12
  • 22