EGit Pull, Push, Merge, not working - eclipse

After pulling updates to a project I am working on with some partners, Eclipse Git is not allowing me to continue pushing, pulling or merging.
When I last pulled the updates, there were conflicts in the web.xml, so I deleted the conflicting text and saved just the correct one. However, Eclipse is continuing to show the double-diamond icon on the web.xml file, indicating there are conflicts. When I try to pull again, I get:
Cannot pull into a repository with state: MERGING
org.eclipse.jgit.api.errors.WrongRepositoryStateException
When I try to push my own commit I get
This is what it looks like in the History view
How do I solve these issues and sucessfully push my commit?

First reset your HEAD from the merge state to previous commit
Add files to Index
Fetch, Pull from the Origin
Merge the branch, Resolve if any conflicts
Commit and Push the Merge

Related

Can't to push commits from local branch to github repository

I was committing and pushing in ordinary for my repository.
but once i used command of git checkout for change to the previous version of my repository.
after that i tried to commit and push, then it can not completed.
i try to use the --no-verify command to push the commit but it also not success.
error: failed to push some refs to 'https://github.com/ruwanliyanage123/Hair-4-U-Hospital.git'
i want to push my commit into github repository
Since you switched to a previous version of your repository, your head is most probably detached. You can't just go back anywhere in your history and make commits.
Consider making a branch from there and then commit to it.
Try to first check in which branch you are working do git branch, check is the one you are working. Then I sometimes do git pull to just make sure that the connection is working this should not delete your progress the you should be able to do git push. If you are afraid youll mess up first do a local back up of all project files except for the .git one which are hidden by default in windows.Lastly I would suggest never posting the actual link to your github repository in case whatever you are working is important, you can just replace with
https://github.com/user/projectname.git

Git: first commit gets lost after the second commit

I only did some commits locally without pushing to the remote by using Eclipse.
And this happened:
After I did the second commit, my first commit disappeared and the files included in the first commit list appeared in the second commit list.
Is this a normal move for git commit?
Is this a consequence of some setting I accidentally made in git configuration?
Or how can I make two commits without being merged automatically because I want to put different comments to them.

Eclipse/Git - Pull Failed Dirty Worktree

As the title states, I'm attempting to pull from a git repository that I'm sharing between my friend and I and I can commit, he can commit, but whenever either one of us attempt to pull it brings back that it failed: DIRTY_WORKTREE
Both of us are extremely new to git, and have zero direction on how to fix this issue.
I was able to fix a similar issue by using the git command line client. While eclipse (egit) was only saying DIRTY_WORKTREE, in the command line I saw multiple conflicting files. Using git merge master from the command line, I could easily resolve the conflicts then in eclipse.
So for me this seems to be an egit issue.
Another approach, if you don't have any work in progress, is to try and reset --hard your HEAD.
With EGit: Resetting your current HEAD:
Select Team -> Reset... on a project. This opens a dialog where you can select a branch or a tag.
Reset HEAD on your current branch, in order to reset index and working tree to the last commit of said branch.
Then try your pull.
I had uncommitted changes. After I committed them, then merged, the dirty worktree issue disappeared.
Just delete the .gitignore present in the project folder, and then merge.
The merge will show conflicts , which you need to resolve and then push the changes.
It seems to mean that the version you are on now has edits that are not yet committed. So you either have to remove these edits, or commit them. Notice that if you commit them you may get merge conflicts.
This error is happening when you have made local changes to files that haven't been committed yet. In git's parlance, you have uncommitted changes in your working tree.
When you are in this situation and you try to pull, git is not sure what to do with the local changes you have. Should it discard those and pull the changes from the remote? Should it commit those before pulling the changes from the remote? That's why it fails.
To avoid this problem before you pull changes into your local repository you either have to commit your local changes, stash them, or discard them. Once you don't have pending local changes in your working tree, you should be able to pull with no errors.
In eclipse I went to Team Synchronizing View and from there right clicked on my project and hit 'overwrite' to overwrite all local changes. Then retry your merge.
Only to add another case, I've got DIRTY_WORKTREE, I'm the only one commiting to my Github project, so in EGit I did a Push branch... with "Force overwrite of branch on remote if it exists and has diverged"
DANGER: If other are working on the same project, this action will delete their commits since divergence.
I had similar problem on Eclipse with uncommited changes as ununiform.
After a commited I could merge and everything is back as it should be.
Take a look at your source code and check any changes. If none you can reset hard.
Delete the affected files and try to pull again. Thereafter push your changes to the git. I has the same issue and this worked for me.
In my case, the DIRTY_WORKTREE was caused by this sequence:
In a commit, I committed also some files that I should have ignored
In the next commit I modified the .gitignore that ignore the above files
Try to rebase on top of another branch where my change to .gitignore is missing
In this scenario, Eclipse thinks your working tree is dirty. Indeed, it is not obvious comparing two filesets when one of the two is ignoring some files and the other is not.
To solve the issue in Eclipse, I did the following:
Modify the .gitignore so it is the same as the one in the branch I want to rebase on
Happily start the rebasing or rebasing with merge.
If you have changes without commiting, eclipse will advise you if you try to pull changes. To solve it, you can discard the changes or do the commit of these files.
Source: https://www.eclipse.org/forums/index.php?t=msg&th=890477&goto=1565668&#msg_1565668
If you want to override you local branch to the origin branch.
Go to Git repo view> click on origin master> Choose reset ->it will show current HEAD and resetting to branch.
Choose HARD reset, if you want to completely overwrite your local changes
I think this problem is caused by EGit version.
When I used Spring Tools Suite with EGit 2.6, I also faced same problems.
EGit is included in STS Default package, so EGit upgrade is very difficult.
Currently I am using eclipse WTP with EGit 3.7, this problem is disappeared.

Switch to another branch in EGit cannot work

I have Branch A and Branch B in the local branch folder.
Branch A is under working.
Now I want to switch to B.
The window pops out:
Checkout Conflicts
The files shown below have uncommitted changes which would be lost by checking out 'master'.
Either commit the changes, stash the changes, or discard the changes by resetting the current branch.
project.properties.
There are 3 options:
Commit..
Stash...
Reset
No matter which option I choose, it does not work.
For example, if I choose "Stash" option, it says:
"The repository does not contain any local changes to stash".
I suspect the egit records have some conflicts, so it cannot know how to do the next step.
The only way:
To remove the local branches, and clone the remote repository to the local?
This needs cost some time for downloading.
I had the same problem. EGit complaint about .class files which were not commited. I deleted the .class files and was able to switch to the desired branch without problems.
IMO removing local branch is not required.
I suggest first to pull the remote changes to local Branch A.
Resolve any conflicts while pulling the changes if any. Refer this video
Add your changes to Git staging area just by dragging the the files from unstaged area to staged area refer pic below.
Click on commit button, then push the changed to remote branch.
After doing this Branch A will be clean, then you can switch to Branch B just by double clicking on it or by right clicking on the repository node and selecting Switch to option in Git repository view.
Also I suggest to use the latest stable Egit plugin from here

Eclipse Egit and Remote Repo Sync

Currently am working with Git Repo and i have a fellow team mate also ,after he commit to the remote repo and i get all the changes . I have couple of questions
When i merge the code with Changes then the changed file in my work space is marked as staged, do i need to commit to local repo?
I have a read lot of documentation and still am confused with the best way of sync,
Currently i do following steps:
Go to Team->Sync Workspace-> Fetch From Upstream->Mege . Please correct if am wrong
Note, the Egit manual includes a "pull" operation which would do the fetch+merge in one operation.
Right-click on a project in the Package Explorer and select Team > Pull or right-click on a repository in the Git Repositories view and select Pull to pull new changes from the upstream branch your local branch is tracking.
Doing a fetch + merge (as in Egit Merging) will result in a merge commit unless there is a conflict.
Real merge: When neither of the conditions above apply egit triggers a merge of the commits. There are two possible outcomes:
If no conflicts occur the current branch will point to a newly created merge commit;
if conflicts occur the conflicting files will be marked with label decorators (see Resolving a merge conflict for further actions in case of merge conflicts).
You should see staged changes only in the second case (merge conflict to resolve), or you would see stage changes because you previously added to the index files which are not part of the merge (they remain staged until you commit them)