69

I am using EGit on Eclipse v4.3 (Kepler). I want to commit and push my changes. I do a pull first and one file is conflicting. After manually resolving the conflict (local and remote are the same now), I am still running into problems.

Here are the error messages for each action:

Push to upstream

master: master [rejected - non-fast-forward]

Pull

Cannot pull into a repository with state: MERGING_RESOLVED

Mark as merged

Failed to add resource to index Failed to add resource to index Exception caught during execution of add command

Hard reset

An internal error occurred during: "Resetting to refs/heads/master". Exception caught during execution of reset command. {0}

How can I remove the conflict and push my changes? What am I doing wrong?

4
  • 2
    Normally you have to add the resolved file to the index (stage it) and then commit the result (for a merge). Could you include the stack trace for "Exception caught during execution of add command"?
    – robinst
    Commented Feb 4, 2014 at 18:24
  • where can I see the stack trace for that? the original message appears in a popup and I have shown the error message when i click on "<< Details". Commented Feb 5, 2014 at 9:19
  • Try the "Error Log" view.
    – robinst
    Commented Feb 5, 2014 at 9:51
  • the error log shows the same as in the question. Commented Feb 5, 2014 at 10:24

10 Answers 10

101

Are you using the Team Synchronise view? If so that's the problem. Conflict resolution in the Team Synchronise view doesn't work with EGit. Instead you need to use the Git Repository view.

Open the Git perspective. In the Git Repository view, go to on BranchesLocalmaster and right click → Merge...

It should auto select Remote Trackingorigin/master. Press Merge.

It should show result:conflict.

Open the conflicting files. They should have an old sk000l >>>> ===== <<<< style merge conflict in the files. Edit the file to resolve the conflict, and save.

Now in the 'Git Staging' view, it should show the changed file in 'Unstaged Changes'. Right click and 'Add to Index'

Enter image description here

Repeat for any remaining files.

Now from the 'git staging' view, commit and push. As Git/Eclipse now knows that you have merged the remote origin changes into your master, you should avoid the non-fast-forward error.

Instead of editing the conflicted file directly, you can use replace with -> ours/theirs to accept one version of all conflicts

replace with their image

4
  • 6
    I have lost a lot of time looking for this. The add to index seems quite unintuitive way to mark a conflict solved. So I just want to colaborate with an image (and have a remainder for the future)
    – borjab
    Commented Feb 10, 2016 at 12:50
  • 2
    Worse here for me. I have merged, staged and committed my conflicting file, but Eclipse doesn't believe me and says there is still a conflict.
    – Adam
    Commented May 11, 2016 at 14:13
  • "Edit the file to resolve the conflict, and save.", is there a way of resolving using 'theirs' / 'mine'? Seems frustrating needing to manually edit a file if you know which version should take priority. Commented Sep 26, 2022 at 14:19
  • 1
    Thanks @AnnanYearian for the idea, i have just tried doing that, and it is going to save me allot of time in the future. Answer updated.
    – dan carter
    Commented Sep 30, 2022 at 7:14
32

I also find it confusing to resolve merge conflicts in EGit. When I am ready to commit some changes to a shared repository, the steps I have learned are as follows:

  1. Right click on the project and choose Team: Commit....
  2. Review my changes to check that I'm not committing any changes I made accidentally or unrelated changes that I forgot about. Write up the commit message while I'm reviewing the changes.
  3. I'm optimistic, so I start by clicking the Commit and Push button. If no one else has pushed any changes, I'm done. If someone has, then the commit succeeds, and the push gets rejected.
  4. Right click on the project and choose Team: Pull. If there are no conflicts, then choose Team: Push to Upstream and I'm done.
  5. If there are conflicts, look through the package explorer to see which files are conflicted. Right click on each conflicted file, and choose Team: Merge Tool. It will show all the changes in both versions of the file, with any conflicts shown in red. Click on the button to merge all non-conflict changes, then edit any red sections manually. There's also a button to show a three way merge that includes the common ancestor.
  6. Save the changes to the file. If you want, you can compare it to HEAD to see what changes you are making on top of the changes you just pulled.
  7. Right click on the file and choose Team: Add to Index to tell EGit that you've finished merging that file. To me, this is the least intuitive step, but the git command line also uses the add command to show that a merge is finished.
  8. Repeat for any other conflicted files.
  9. When all the files are merged, right click on the project and choose Team: Rebase: Continue Rebase. If there are more conflicted commits, go back to dealing with conflicts.
  10. When the rebase is complete, run your tests to see that the rebase didn't break anything.
  11. Right click on the project and choose Team: Push to Upstream.
4
  • I'm in a similar situation, but I see nothing called "Team: Rebase: Continue Rebase". Where did you access that option?
    – pgreen2
    Commented Jan 6, 2016 at 15:37
  • The colons represent child menus, @pgreen2. I right clicked on the project and navigated the listed menus. It's possible we're using different versions - I use Eclipse 4.4.2 (Luna) with EGit 3.4.2. If you can't find what I describe, look at EGit's rebase documentation. It sounds like there's a Continue button in the Git Staging view and something in the Git Repositories view.
    – Don Kirkby
    Commented Jan 6, 2016 at 19:31
  • My experience following this route (thanks btw - I'm not bashing you) is that I could do a merge, then 'mark as merged', then 'commit' but egit still wouldn't let me push the commit to the remote. After an hour of faffing around, I tried pushing again and this time it let me. No idea why.
    – Adam
    Commented May 11, 2016 at 14:42
  • Worth doing a pull before commit, just to help avoid conflicts.
    – MikeW
    Commented Jun 17, 2019 at 14:01
8

This guide was helpful for me http://wiki.eclipse.org/EGit/User_Guide#Resolving_a_merge_conflict.

UPDATED Just a note on that about my procedure, this is how I proceed:

  1. Commit My change
  2. Fetch (Syncrhonize workspace)
  3. Pull
  4. Manage Conflicts with Merge Tool (Team->Merge Tool) and Save
  5. Add each file to stage (Team -> Add to index)
  6. Now the Commit Message in the Stage window is prefilled with "Merged XXX". You can leave as it is or change the commit message
  7. Commit and Push

It is dangerous in some cases but it is very usefull to avoid to use external tool like Git Extension or Source Tree

2
  • should I add pull generated files also to stage along with conflict resolved files in step 5?
    – Mr code.
    Commented Oct 3, 2019 at 4:18
  • Those files should be added automatically into the stage but if not then yes, you have to manually add them
    – Tonino
    Commented Oct 3, 2019 at 8:13
4

I know this is an older post, but I just got hit with a similar issue and was able to resolve it, so I thought I'd share.

(Update: As noted in the comments below, this answer was before the inclusion of the "git stash" feature to eGit.)

What I did was:

  1. Copy out the local copy of the conflicting file that may or may not have any changes from the version on the upstream.
  2. Within Eclipse, "Revert" the file to the version right before the conflict.
  3. Run a "Pull" from the remote repository, allowing all changes to be synced to the local work directory. This should clear the updates coming down to your filesystem, leaving only what you have left to push.
  4. Check the current version of the conflicting file in your work directory with the copy you copied out. If there are any differences, do a proper merge of the files and commit that version of the file in the work directory.
  5. Now "Push" your changes up.

Hope that helps.

4
  • Can you explain where the Git stash feature is in eGit? I haven't seen it there and this is a question regarding eGit.
    – B.Kaatz
    Commented Jun 30, 2015 at 1:20
  • Hmmm... I don't seem to have that available on mine. I'm running MyEclipse2015Cl (built from Eclipse v4.4.0) with the eGit 3.4.2 plugin. Must be a feature from a more recent version. :-/ Now, noting that the 3.4.2 version of eGit was released December 18th, 2014 and I gave my answer July 23rd, 2014, you down-voted me because you found a feature that wasn't even available when I gave my answer, let alone when the OP posted their question? Thanks.
    – B.Kaatz
    Commented Jul 16, 2015 at 21:45
  • @chrisinmtown you should add your stash solution as a separate answer.
    – Adam
    Commented May 11, 2016 at 14:44
  • Thanks for updating the answer, objection withdrawn :). I moved my comments into a separate answer per @Adam's suggestion Commented May 14, 2016 at 9:48
2

As it's an issue we face more than often, below are the steps to resolve it.

  1. Open the Git perspective. In the Git Repository view, go to on BranchesLocalmaster and right click → Merge...

  2. It should auto select Remote Tracking → *origin/master. Press Merge.

  3. Launch stage view in Eclipse.

  4. Double click the files which initially showed conflict

  5. In the conflict merge view, by selecting the left arrow for all the non-conflict + conflict changes from left to right, you can resolve all the conflicts.

  6. Save the merged file.

  7. Do a Team → pull from Eclipse again.

You are all set :)

2

Just right click on a conflicting file and add it to the index after resolving conflicts.

2

An earlier process of resolving conflicts (through the staging view) in Eclipse seemed much more intuitive several years ago, so either the tooling no longer functions in the way that I was used to, or I am remembering the process of resolving merge conflicts within SVN repositories. Regardless, there was this nifty "Mark as Merged" menu option when right-clicking on a conflicting file.

Fast forward to 2019, I am using the "Git Staging" view in Eclipse (v4.11). Actually, I am using STS (Spring Tool Suite 3.9.8), but I think the Git Staging view is a standard Eclipse plugin for working with Java/Spring-based projects. I share the following approach in case it helps anyone else, and because I grow weary or resolving merge conflicts from the GIT command line. ;-)

Because the feature I recall is now gone (or perhaps done differently with the current version of GIT and Eclipse), here are the current steps that I now follow to resolve merge conflicts through Eclipse using a GIT repository. It seems the most intuitive to me. Obviously, it is clear from the number of responses here that there are many ways to resolve merge conflicts. Perhaps I just need to switch to JetBrains IntelliJ, with their three-way merge tool.

  1. Double-click on the offending file
  2. A "Text Compare" interface appears, with side-by-side views of the conflicting commits.
  3. Identify which view is the local state of the file, or the most recent commit.
  4. Make changes to the local window, either adding or redacting the changes from the offending commit.
  5. When the desired set of changes has been reviewed and updated, right-click on the unstaged file.
  6. Click the "Add to Index" option, and your file will be added to the staged changes.
  7. This also removes the conflicting file from the unstaged list, thus indicating that it has been "marked as merged"
  8. Continue this process with each additional file in conflict.
  9. When you have reivewed all conflicting files, confirm that all desired files (including additional changes) are staged.
  10. Add an appropriate commit message.
  11. Commit and push the "merged" files to the origin repository, and this officially marks your files as merged.

NOTE: Because the menu options are not intuitive, a number of things can be misleading. For example, if you have saved any updates locally, and try to reopen the conflicting file to confirmand that the changes you made have persisted, confusion may result since the original conflict state is opened... not your changes.

But once you add the file(s) to the index, you will see your changes there.

I also recommend that when you pull in changes that result in a merge conflict, that you "stash" your local changes first, and then pull the changes in again. At least with GIT, as a protection, you will not be allowed to pull in external changes until you either revert your changes or stash them. Discard and revert to the HEAD state if the changes are not important, but stash them otherwise.

Finally, if you have just one or two files changing, then consider pulling them into separate text files as a reference, then revert to the HEAD and then manually update the file(s) when you pull changes across.

1
  • Thank you, especially the part about opening up the local file after having done the merge changes. That is confusing as hell. If you open the file via eclipses package explorer, you will get a file as git would produce it with conflict markers. If you open the file directly via file explorer, you will see the before-merge version. The only way to get what will actually be committed is via the "Git staging" view and then double clicking it in the "Staged Changes" area.
    – wlfbck
    Commented May 25, 2020 at 12:23
0

This approach is similar to "stash" solution but I think it might be more clear:

  1. Your current local branch is "master" and you have local changes.
  2. After synchronizing, there are incoming changes and some files need to be merged.
  3. So, the first step is to switch to a new local branch (say "my_changes"):
    • Team -> Switch To -> New branch
      • Branch name: my_changes (for example)
  4. After switching to the new branch, the uncommitted local changes still exist. So, commit all your local uncommitted changes to the new branch "my_changes":
  5. Switch back to the local "master" branch:
    • Team -> Switch To -> master
  6. Now, when you choose Team -> Synchronize Workspace, no "merge" files are expected to appear.
  7. Select Team -> Pull
    • Now the local "master" branch is up to date with respect to the remote "master" branch.
  8. Now, there are two options:
    • Option 1:
      • Select Team -> Merge to merge the original local changes from "my_changes" local branch into "master" local branch.
      • Now commit the incoming changes from the previous step into the local "master" branch and push them to the remote "master" branch.
    • Option 2:
      • Switch again to "my_changes" local branch.
      • Merge the updates from the local "master" branch into "my_changes" branch.
      • Proceed with the current task in "my_changes" branch.
      • When the task is done, use Option 1 above to update both the local "master" branch as well as the remote one.
0

To resolve the conflicts, use Git stash to save away your uncommitted changes; then pull down the remote repository change set; then pop your local stash to reapply your uncommitted changes.

In Eclipse v4.5 (Mars) to stash changes (a relatively recent addition, wasn't in previous EGit) I do this: right-click on a top-level Eclipse project that's in Git control, pick Team, pick Stashes, pick Stash Changes; a dialog opens to request a stash commit message.

You must use the context menu on a top level project! If I right click on a directory or file within a Git-controlled project I don't get the appropriate context menu.

1
  • Thanks @Peter Mortensen for the cleanup :) Commented Jun 27, 2018 at 14:15
0

GIT has the most irritating way of resolving conflicts (Unlike svn where you can simply compare and do the changes). I strongly feel git has complex conflict resolution process. If I were to resolve, I would simply take another code from GIT as fresh, add my changes and commit them. It simple and not so process oriented.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.