[eclipse] How to resolve conflicts in EGit

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?

This question is related to eclipse git egit

The answer is


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.

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.

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


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.


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


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 Branches ? Local ? master 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 :)


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.


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.


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.


Examples related to eclipse

How do I get the command-line for an Eclipse run configuration? My eclipse won't open, i download the bundle pack it keeps saying error log strange error in my Animation Drawable How to uninstall Eclipse? How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Class has been compiled by a more recent version of the Java Environment Eclipse No tests found using JUnit 5 caused by NoClassDefFoundError for LauncherFactory How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running with Java 9 "The POM for ... is missing, no dependency information available" even though it exists in Maven Repository The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat

Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to egit

How to resolve conflicts in EGit Push eclipse project to GitHub with EGit Egit rejected non-fast-forward 'cannot open git-upload-pack' error in Eclipse when cloning or pushing git repository Eclipse EGit Checkout conflict with files: - EGit doesn't want to continue git stash and git pull How do I set up Eclipse/EGit with GitHub? "Auth Failed" error with EGit and GitHub