How can I get rid of Eclipse Git "conflict" icons after all merges are resolved? - eclipse

I get the Git conflict icon in Eclipse on lots of files, even though it seems that I resolved any possible conflicts.
In Eclipse 4.5.2, in the Project view, I select a project root and do right-click -> Compare to branch origin/master. Next, we see the Team Synchronization view. Many files show a red conflict icon., but they should not.
The Git staging view, which is supposed to show conflicts, is empty. I already tried Merge; Committing the merge (nothing remains to be committed). I tried Add to Index from the Git Staging view; and even Overwrite from the Team Synchronization view. Comparing the local and origin files shows that they are identical.
Git setting autocrlf is true, so that is not the issue.
This occurs repeatedly.
Why do I see this conflict icon? How can I get rid of it?

Did you do a pull? Or where you just comparing in Team Synchronization? In my experience the Team Synchronization perspective confuses the most people.
In general it should be used "read-only". Don't try to resolve any conflicts here. Per default you are comparing your working copy against the remote repository. Which means you actually have no conflict in your working copy. When you "fix" them here you are just making a local modification. You can commit that but it doesn't resolve any conflict. It makes the actual conflict even harder to resolve.
So don't do anything in the Team Synchronization perspective. Just do a pull to have those conflicts in your working copy and then resolve them. A merge conflict is marked as merged by moving them to the Staged Changes.
If something breaks and you want a new try do a reset --hard on the last commit in your local repository.

After editing the conflict resource properly. Right click on the conflict resource and click on *Mark as Merged".
See Resolving_a_merge_conflict. Also check this screen cast.

Related

How to correct «unable to merge unrelated histories»?

I use github desktop (https://desktop.github.com ) while developing the application with several other people, so, for some reason, when trying to merge two branches into one, the error "unable to merge unrelated histories" is displayed for one of the target branches.
What could be the problem?
First of all: You may also be able to find a solution using the search.
Potential reasons for the error message
From: https://komodor.com/learn/how-to-fix-fatal-refusing-to-merge-unrelated-histories-error
Here are some common scenarios where fatal: refusing to merge unrelated histories can occur.
You have a new Git repository with some commits. You then try to pull from an existing remote repo. The merge becomes incompatible because the histories for branch and remote pull are different. Git sees the situation as you trying to merge two completely unrelated branches, and it doesn’t know what to do.
There’s something wrong with the .git directory. It may have been accidentally deleted at some point or got corrupted. This can happen if you’ve cloned or cleaned a project. Here the error occurs because Git doesn’t have the necessary information about your local project’s history.
The branches are at different HEAD positions when you try to push or pull data from a remote repo and cannot be matched due to a lack of commonality.
Options to resolve the issue
The article describes two options on how to resolve/avoid such issues but targets command line /terminal users. I guess I would prefer option 2 over option 1 anyway, also using git in the terminal.
The article explains it like this:
The alternative (and longer) way of fixing refusing to merge unrelated histories issues is to unstage your current commits, stash them, clone your required remote repository, and then place your stashed branch contents into the new clone. This will ensure that any conflicts that you may encounter in the code are addressed before merging and prevent application errors from occurring.
How it (should) work in GitHub Desktop
In GitHub Desktop you should be able to use a modified version of option 2:
To unstage all the files in your last commit, double click staged files. This moves them to the unstaged area. Learn more in this GitHub issue.
To stash your unsaved files, right-click an unstaged file. Learn more about stashing files.
This will give you a clean working tree to pull your remote repository into. Once you’ve successfully pulled into your branch, you can:
unstash your files (see link above again) to reapply them to your current working copy.
commit them as a separate commit.
resolve any file conflicts that you may have.
I hope this explanation adds some clarity. Let me know if there are any wrong or misleading information in my text please.
This problem has several reasons.
But probably your project clone just differs from GitHub (main project).
First of all, save your project (because you probably don't want to code everything again).
Remove repo from GitHub desktop (not GitHub!!!)
Go to the project page in GitHub
Click code, open with GitHub Desktop, and code again.

How do I get back my files marked as deleted in the unstaged changes area of Git staging?

I'm running Eclipse Kepler Service Release 1 with egit for versioning. I've been using eclipse and egit for just a few months and am not up on all of it's intricacies yet. I've found some related questions here for git, but I don't really understand how to use egit to accomplish what the answers propose.
The immediate problem I have is that no files are visible in the project tree except for the libraries and WEB-INF under war. The files show up in the unstaged changes area of the Git staging window marked with an x as deleted. This is a jsp project running google app engine if it matters.
What got me to this point was attempting to checkout the master branch. I got an error saying the branch could not find 2 files and afterwards my working files in the current branch disappeared. The Git repositories view shows my current branch is the same as the one I had been working on, so these files should normally be visible.
Since I never chose to delete these files I have no idea what stage egit thinks it's in. I don't have a backup and my other branches haven't had recent changes merged in.
You can always see the state of Git as a text decoration next to each repository node in the repositories view of the Git perspective. Normally that should only show the branch name, but it might also be something like "Interactive rebase", if Git stops for user input in the middle of an operation.
If that is not showing the branch name you want, then just the context menu Switch->[branchname] should bring you back to the wanted branch.
If everything else fails, you can always throw away all local changes and have your local working directory reset to the state of any commit (or branch) by using context menu->Reset->Hard and select the commit (or branch) to which you want to reset. Be aware that this wipes out any uncommitted local changes.
In case of more questions, you should read the very detailed EGit user guide.

egit pull with uncommitted changes

I'm working on a project in Eclipse that was cloned from a GIT remote repository. The Eclipse eGit plug-in allows you to get going without really understanding anything about GIT, which is where I was. I've eventually realized that when I do a "compare with HEAD revision" I'm not as I first thought comparing with the remote repository, but with my local repository. I understand now that I need to pull updates from the remote repository, but it's not clear what will happen to my local changes. I've not committed these changes, partly because I thought I might be updating the remote repository (I realize now that I won't) but partly because I find the Package Explorer file decoration (">") is useful in identifying the files I've modified. If I commit then I assume these indications will disappear.
My questions:
How do I update my local repository without losing my changes?
Can I do this without losing my modified file indicators?
Update: I thought I understood how some of this worked, but I'm really lost now, particularly by the relationship between workspace and (local) repository.
I used Team->Pull to update my repository. Since I've not committed any changes, I expected this to work without conflict, but it flagged up all the changes between the workspace and repo as conflicts (confusion #1).
I assumed I needed to use Team->Synchronize to bring changes into the workspace, as I would with other VCSs. When I do, I see the changes, but not even the non-conflict updates have been applied to the workspace and there is no "Update" operation to do this, so I don't know how to apply them (confusion #2).
For the conflicting updates, I manually merged the changes into the workspace copy and used "Mark as merged", but this seems to do nothing. The conflict is not cleared. I would expect at this point the change would just be an uncommitted change in the workspace (confusion #3).
I read elsewhere that to remove conflicts I should use Team->Add and Team->Commit, but I don't want to commit my changes as I explained originally (confusion #4).
You can see I'm confused! Any help will be much appreciated.
If git pull does not work, you can use this:
git stash
git pull
git stash apply
not sure eclipse supports stash, so you may have to use the command line.

Changing git branch while working with eclipse (what's proper order)?

my problem is that sometimes I change git branch while working live in eclipse. But I do not know what should I do (in what order to to, to don't make mess in both projects).
So my procedure is:
eclipse is open (working on some problems)
git change branch
eclipse > selecting projects and clicking to refresh
work on eclipse, continue job
Is it all right or I should use first Clear&Build and then refresh projects? What do you think, is it important witch order do this while changing branch ? Please help because I am working with friends on big project and I do not want break anything.
If you are working on a particular branch and you want to preserve whatever it is you have been doing, you should add or commit those changes first (git add or git commit) to that branch before changing to a different branch.
If you have the same projects in both branches, then refreshing the projects after changing branch should be fine, but ideally followed up with a clean/build.
If you want to be really safe, you can first close the projects before changing branch, then refresh and re-open them after changing branch.

Why is the merge tool disabled in Eclipse for a EGit-managed project?

As per the EGit User Guide, to use the merge tool, one should right-click on the resource with a merge conflict and then select Team > Merge Tool. However, when I do this, the Merge Tool option is greyed out. EGit is properly detecting the conflict and showing me both the icon and text label decorations for the file in conflict.
Any ideas?
It was disabled for me because I had some changes on my stash list.
$ git stash clear
fixed the problem for me.
It can depend on the version of EGit you are using, and on the operation that lead to the conflict.
See for instance bug 339092 which mention merge tool being not enabled in the case of a conflict after cherry-picking: only the just released EGit 0.12 would support that.
The only time (other than a bug) that the Merge Tool would be disabled is that when you are in any status other than the Conflicts one; i.e. you will only see that option enabled when the status is Conflicts. The status is shown next to the project name in most views, such as Project Explorer and Synchronize.
Make sure you have merged with desired branch, then if your merge results in conflicts, your project will enter Conflicts mode, and the Merge Tool will be enabled.
It seems to be a bug in EGit as VonC mentioned, but the fix is easy. I did it using reset branch option on the same menu that Cherry Pick option existed.
Note: git stash clear didn't help.
This happens if you tried to push changes to a remote and there were merges required from the remote. It fails with 'not FF' but also simultaneously detects the conflict. Don't ask me why it doesn't mark the whole project as conflicted at this point.
Open the Synchronize tab, right-click the project and select 'merge'. This immediately fails because of the conflicting file, and it switches on the conflict icon label for the project and enables the 'merge tool' option.
This is for EGit 4.0.3 in Eclipse Mars.
This also happens if you're in detached head state (in my case, I had checked out a remote branch and then forgotten).
Also, even after you've corrected the problem, you may have to select a different project and then reselect the one you actually want (just selecting in the package explorer view) in order for the menu to update.