egit pull with uncommitted changes - eclipse

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.

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 to merge deleted/changed file in eGit

The case:
Locally, I have a commit where I have deleted a file. Remotely, someone else have changed this file.
Now, when I merge, I find that git has the put the changed file in my working tree. This is probably the way git works, and in git command line, I'd be able to use git mergetool to choose between the deleted or changed file.
In eGit, however, how would I make this choice?
We ended up with a quite unusable work-around where we first addded the file to the index and then deleted it in working tree and then saved this change (deletion) to the index.
Technical info:
The version of eGit (feature) we're using is 4.9.2.201712150930-r.
The version of git we're using is 2.16.1
Background:
My team have recently moved to using Git as our revision control system. There's a general wish from team members to use an integrated solution and since we're working with Eclipse, eGit seemed to be the way to go.
I would suggest that all your team members follow this process:
Commit your changes to your local repository.
Pull with rebase to merge with the remote origin branch.
Resolve the conflicts, if any. In your case, if you deleted the file before the other team member modified it, then that person would have noticed that the file has been deleted.
Push the commit upstream.
This process has worked for us. Hope this helps.

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

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.

git eclipse always have to pull allready updated project

I have this strange behaviour from git, and even if i'll describe it from eclipse egit plugin, from terminal i have the same issue.
I have a project in the workspace that is shared between me and other developers, when i sync the project it says to me that i have to push something like 14/16 commit ant i have to pull one, even if had no commit at all.
Every time that i do the pull it seems that the project is now synchronized, so i push "team syncronize" again and the 14/16 commit to pull appears again.
That's not the only strange thing, another one is that i can push commit to remote after i have pull those commits but the other developers couldn't, even if they do the same things that i've done, it says to them that the problem are a "dangling blob".
Before write some of the solutions that i have found and what i have try i want to say that the number of commits are practically the entire history of the project.
I have tried to use the manual gc of git in the remote repository after i have done an fsck, where i have met effectively two dangling commit (why two dangling commit and egit says one dangling blob? i don't know....), this have removed the two dangling commit, so i have deleted the project from my workspace clone it again, but the same error happens again.
So i have used this other solution http://www.tekkie.ro/news/howto-remove-all-dangling-commits-from-your-git-repository/, always on the remote repository but the problem is still the same.
So even if have read practically all the documentation i didn't undestand somethings:
1) what's the difference between dangling commit and dangling blob?
2) how a dangling commit/blob happens?
3) how can i restore the project's repository?
UPDATE
I start a bounty because i really want to undertand and solve the problem, so for that i'll be clear in what i need to understand:
I have a project that everytime i use team syncronized, want to re-pull all the history, not only to me but for every one ofe my colleague, we use gitblit as remote repos. What can i do? Where do i have to search the possible errors?
UPDATE
that's EGIT
and that's the Terminal
This is only a answer to some of your issues, maybe it should a comment instead.
Commits and blobs (blobs contains file content) are all objects in the git DAG and an object becomes 'dangling' (unreachable, orphan or loose) when nothing reference it (i.e. not part of the history) and git will clean up dangling objects if you run git gc (removes dangling objects older than 2 weeks) and some git commands will also run git gc --auto when they are done with their operations.
When you make changes in the DAG (i.e. rebase, amend or re-add content to the index) some objects will be replaced with new ones and the old objects then becomes dangling.
You can run git fsck --unreachable to find objects that are dangling.
Note: Objects referenced by reflog are normally not considered dangling.
In your case you may need to run git prune, git gc --agressive or git gc --prune=now to remove all dangling objects (do not forget to make a bakup first, just in case)

cvs: updates fail to merge

I've just discovered, a surprising for me behavior of cvs.
I change file1 localy
During this time people change other unrelated parts of the same file, and commit to the repository
I update my local copy from repository
At this point I expect my local copy of file1 to contain all changes made by others to this file, unless the update above reported a conflict. However, when I do now diff with head, I discover lot's of differences coming from changes made by others in parts of the file that I did not touch at all.
Any ideas? Is this just the limited abilities of cvs to merge? Any wrong setting? Something in my workflow?
CVS has very limited merge facilities. Switch to a modern system such as Git (perhaps via git-cvsimport if the repo maintainer is uncooperative) if you want a better merge experience. See also Best practices for using git with CVS
The final solution is :
1. Save your local code to another place manually
2. Revert the files which may has conflict to the HEAD (most latest) version on CVS server.
3. Add back your change to the Reverted file.
The concept for above solution is to CLEAR UP all the possible issue by REVERT and get a 100% clean version from repository then add back our changes.
It can resolve below issues which caused by code out of date / code base messed up.
CVS commit had a conflict and has not been modified
CVS update failed
CVS not sync