0

I am quite new with Gitlab and I'm having an issue for merging in Eclipse. We're working as a team, and we all have development branches that we are trying to merge into a single one. Unfortunately, when I did my merge, I have done a stupid mistake. Instead of merging my development branch to the main one, I have merged the main one into my development branch.

I have reversed the commit/merge on gitlab, but now as I try to merge back my development branch into the main one on Eclipse, it seems like I am 9 commits ahead of this branch (described as the arrows on Eclipse here: Screenshot), so the potential merge would basically replace everything by my code, when I should actually have merge conflicts to solve.

I am not quite sure how to merge properly so that I get back these merge conflicts.

Here is a screenshot of my network: Screenshot

The ['1'] commit in the network on the left branch (my branch) corresponds to the merge from Week6AllIssues to my dev branch (the wrong merge). The last commit on this left branch is me reversing the commit.

Thanks a lot for your help !

Renats Stozkovs
  • 2,549
  • 10
  • 22
  • 26
Pierre
  • 3
  • 1
  • Are you using the branch with anyone else? Did you place the commits on Gitlab? Have you tried `git reset --hard ` (here's how you do this in Eclipse: https://wiki.eclipse.org/EGit/User_Guide#Reset_.3E_Soft.2FMixed.2FHard)? – Pavel Vergeev Apr 16 '17 at 19:05
  • I am the only one who is using the branch, and I have done all the commits on Eclipse. I've done the reverting commit on gitlab though. It did not seem to do a revert merge, but a revert commit I guess it is kind of the same ? Anyway I'm gonna try what you've just sent me, so the solution would be to reset my branch to the commit before the merge right ? Thanks a lot, I keep you updated – Pierre Apr 16 '17 at 19:10
  • Right. Th revert commit actually adds a commit, and reset removes them. This isn't something you would normally use, but it appears appropriate in your situation. – Pavel Vergeev Apr 16 '17 at 19:12
  • So would resetting hard actually erase that wrong merge from my network, and I could proceed as before for merging correctly ? Thank you ! – Pierre Apr 16 '17 at 19:16
  • After `git reset` the superfluous commits will be removed from the local branch. If after that they remain on the remote branch corresponding to your local branch, just use `git push --force` (here's how you do it in Eclipse: https://stackoverflow.com/questions/12302171/egit-on-eclipse-how-to-git-push-force). – Pavel Vergeev Apr 16 '17 at 19:23
  • It seems to be almost there, but when I try to push force on Eclipse it gives me an error like this: {rejected - non-fast-forward} unfortunately. Sorry and thank you again for helping me a lot – Pierre Apr 16 '17 at 19:41
  • Have you tried `configure push - enable "force update"` option? This should work. – Pavel Vergeev Apr 16 '17 at 19:46
  • It ended up working ! Thanks a lot ! – Pierre Apr 19 '17 at 12:38
  • I'm happy to hear it! I've summarized our discussion in an answer so that others could benefit from it. I'd appreciate if you mark it as an answer to the question. – Pavel Vergeev Apr 19 '17 at 13:00

1 Answers1

0

If you're not using the remote branch with anyone else, the following series of steps might help.

First, remove the superfluous commits from the local branch. It can be achieved with git reset --hard <the commit before you merged master into your branch> command (see this link on how to do this with Eclipse).

Now make the remote branch match your local branch. You can do this with git push --force command. In Eclipse, this command corresponds to configure push - enable "force update" option.

Now the superfluous commits are gone.

Pavel Vergeev
  • 3,060
  • 1
  • 31
  • 39