简体   繁体   中英

How to revert changes due to a merge with Eclipse and EGit

I am using Eclipse Mars.1 (4.5.1) with EGit 4.1.0.

After a merge from a branch into master, I cannot figure out how to tell EGit to resolve a conflict by simply keeping the version that was in master before the merge, ignoring anything that came into that file as a result of the merge.

This is what I do. My Java projects all point to master. No uncommitted changes in any project.

In Package Explorer view I right-click a project, click Team, Merge.

In the "Merge 'master'" dialog that pops up I select a branch (under "Local"), I leave the "Merge options" on "Commit" and the "Fast forward options" on "If a fast-forward, only update the branch pointer".

I click "Merge". The "Merge Result" dialog pops up and says "Result Conflicting". Fair enough, I was expecting conflicts and I'm going to resolve them manually one by one.

Now, my problem is that for some of the files in conflict the way I want to resolve the conflict is simply to reject any change to that file resulting from the merge; just keep that file as it was before I did the merge. This should be trivial to do (at least in SVN it was), but I cannot see anywhere in Eclipse how to do that. The merge has filled the file with the "<<<<<<" conflict markers and I just don't see what needs to be done to revert those changes only in that file so that that file simply becomes unchanged with respect to master, which is where all the projects are pointed.

If I right-click on the file in the Synchronize view and select "Overwrite", I am asked if I "want to overwrite local changes". That's exactly what I want, I want the file to have no local changes, so I click Yes. But the result is that the file gets deleted locally, although it exists both in master and in the branch. It disappears from Package Explorer, and since I also had it open in the editor, that editor tab closes away. That's not what I meant by "overwrite local changes" and I don't understand why it happens.

If instead of "Overwrite" I select "Mark as merged" (although the conflict markers are still there), the file is no longer shown as in conflict, but it still has all the conflict markers in it and of course is still shown as changed, while I want it to be unchanged with respect to master.

And if instead I resolve all the conflicts in the other files and I want to commit all the files except the problematic one - so that that one will stay unchanged - when the commit dialog shows up and lists all the files to be committed, each with a checkbox, and I click on the checkbox of the problematic file to exclude it from the commit, the checkbox doesn't get unchecked, and this goes for any of the other files; the checkboxes don't look disabled, but they don't respond to the click.

What am I missing ?

This problem got solved for me in the following way. I don't think it's the proper way (and I'm still interested in hearing about that if anyone knows) because it involves switching between two different Eclipse views, but at least this did the trick for me, and the only reason why this involves the "Synchronize" view is that nowhere else can I find the "Mark as merged" menu entry when I right-click on a file in conflict (neither in the "Git Staging" view nor in Package Explorer).

  • Open the "Git Staging" view. The files in conflict are shown under "Unstaged Changes".

  • Among them, right-click the one for which you just want to revert any change resulting from the merge in order to just keep the file unchanged. Then select "Replace With / Ours".

  • Go to the "Synchronize" view, right-click the file, Mark as Merged.

  • Now in Package Explorer the file should be shown as not in conflict, just unchanged, so it won't be included in a commit.

截至目前,结帐仅在EGit暂存视图中的冲突文件上可用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM