Reputation: 4736
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?
Upvotes: 69
Views: 266541
Reputation: 4361
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 Branches → Local → master and right click → Merge...
It should auto select Remote Tracking → origin/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'
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
Upvotes: 103
Reputation: 1379
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.
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.
Upvotes: 2
Reputation: 235
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.
Upvotes: 0
Reputation: 197
Just right click on a conflicting file and add it to the index after resolving conflicts.
Upvotes: 2
Reputation: 4728
As it's an issue we face more than often, below are the steps to resolve it.
Open the Git perspective. In the Git Repository view, go to on Branches → Local → master and right click → Merge...
It should auto select Remote Tracking → *origin/master. Press Merge.
Launch stage view in Eclipse.
Double click the files which initially showed conflict
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.
Save the merged file.
Do a Team → pull from Eclipse again.
You are all set :)
Upvotes: 2
Reputation: 4374
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.
Upvotes: 0
Reputation: 1
This approach is similar to "stash" solution but I think it might be more clear:
Upvotes: 0
Reputation: 1166
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:
It is dangerous in some cases but it is very usefull to avoid to use external tool like Git Extension or Source Tree
Upvotes: 8
Reputation: 181
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:
Hope that helps.
Upvotes: 4
Reputation: 56240
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:
Upvotes: 32