Switch to another branch in EGit cannot work - egit

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

Related

Github with eclipse error [duplicate]

I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.
I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.
Anyway, on to the steps.
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
In detail...
In eclipse, open the view 'Git Repositories'.
Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.
Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.
In my case I chose the Force Update checkbox while pushing. It worked like a charm.
In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
cloned git repository
made some changes in source code
staged changes from Git Staging View
finally, commit and Push!
And I faced this issue with EGit and here is how I fixed it..
Yes, someone committed the changes before I commit my changes. So the changes are rejected.
After this error, the changes gets actually committed to local repository.
I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - In what cases could `git pull` be harmful?
So, I executed following steps
from Git Repository perspective, right click on the concerned Git
project
select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'?
select Rebase... - this open a popup, click on Preserve merges during rebase see why
What exactly does git's "rebase --preserve-merges" do (and why?)
click on Rebase button
if there is/are a conflict(s), go to step 6 else step 11
a Rebase Result popup would appear, just click on OK
file comparator would open up, you need to modify left side file.
once you are done with merging changes correctly, goto Git Staging view
stage the changes. i.e. add to index
on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
from History view, select your commit row and select Push Commit
select Rebase Commits of local....... checkbox and click next. refer why - Git: rebase onto development branch from upstream
click on Finish
Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.
Configure
After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
Make sure you select the force update
Finally save and push the code to the repo
Open git view :
1- select your project and choose merge
2- Select remote tracking
3- click ok
Git will merge the remote branch with local repository
4- then push
This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.
In my case i forgot to pull the new changes from git
Right click on the project Fetch From Upstream
Right click on the project Pull
Right click on the project Push to Upstream
I have found that you must be on the latest commit of the git.
So these are the steps to take:
1) make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error.
2) pull the latest changes.
3) commit your updates.
Hope this helps.
Go in Github an create a repo for your new code.
Use the new https or ssh url in Eclise when you are doing the push to upstream;

How can I retrieve the local changed files which I wrongly reset in git

Below is the situation which explains what's the matter about git.
I was using the 'develop' branch and already made several changes to the local files such as .sql, .java, .js...
I made a local branch called 'develop_some_future' since my boss wants to confirm my changes before merging main 'develop' repository.
Apparently my local file changes #'develop' branch have applied to 'develop_some_future' branch and I started editing local files again.
For some reason, I tried to pull the files that my co-workers already committed, but it has failed(Probably I couldn't set 'develop_some_future' branch well). So, I changed current branch to 'develop' branch and tried to pull them.
Fortunately it got worked, and then I tried to back to the 'develop_some_future' branch.
A dialog pops up suddenly while changing the branch and asked me that 'your local change for "~~~.sql" would be deleted since it's not committed yet. To avoid this, please commit that file or choose reset.'
Because I thought only '~~~.sql' would be changed to the latest committed state and that was not a problem, I selected 'reset' button, but unfortunately all local changes have gone.
Anyone knows how can I retrieve the date before reset?
I found that both 'git reflog' and 'git reset HEAD{}' commands are useful.
However, git reflog shows only commit, merge, and checkout changes and so I can't find reset status at all.
I'm afraid your files are gone for good, unless you had previously staged the file somehow (add or stash save).
If it had been staged, a blob object was created by Git which is now dangling (git fsck will tell you dangling objects). You can then resurrect the file by writing the blob's content with git cat-file to a new file.
If not, your'e screwed, and you have to do your work again.
It seems the problem arose in the first place, because you thought that unstaged/uncommitted changes belong to the current branch. They do not, and only live in the working directory. They will be carried over when switching branches (unless, of course, the same file was modified in the branch. Git will then refuse to checkout the other branch).

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.

Egit rejected non-fast-forward

I am getting this message while pushing to github repository. Can you tell me step by step procedure to fix it? I pushed only once and it was successful. But, when I updated a project and tried to push my second commit, it shows "master rejected non-fast-forward" and does not allow me to push. Please explain the procedure.
I had this same problem and I was able to fix it. afk5min was right, the problem is the branch that you pulled code from has since changed on the remote repository. Per the standard git practices(http://git-scm.com/book/en/Git-Basics-Working-with-Remotes), you need to (now) merge those changes at the remote repository into your local changes before you can commit. This makes sense, this forces you to take other's changes and merge them into your code, ensuring that your code continues to function with the other changes in place.
Anyway, on to the steps.
Configure the 'fetch' to fetch the branch you originally pulled from.
Fetch the remote branch.
Merge that remote branch onto your local branch.
Commit the (merge) change in your local repo.
Push the change to the remote repo.
In detail...
In eclipse, open the view 'Git Repositories'.
Ensure you see your local repository and can see the remote repository as a subfolder. In my version, it's called Remotes, and then I can see the remote project within that.
Look for the green arrow pointing to the left, this is the 'fetch' arrow. Right click and select 'Configure Fetch'.
You should see the URI, ensure that it points to the remote repository.
Look in the ref mappings section of the pop-up. Mine was empty. This will indicate which remote references you want to fetch. Click 'Add'.
Type in the branch name you need to fetch from the remote repository. Mine was 'master' (btw, a dropdown here would be great!!, for now, you have to type it). Continue through the pop-up, eventually clicking 'Finish'.
Click 'Save and Fetch'. This will fetch that remote reference.
Look in the 'Branches' folder of your local repository. You should now see that remote branch in the remote folder. Again, I see 'master'.
Right-Click on the local branch in the 'Local' folder of 'Branches', which is named 'master'. Select 'Merge', and then select the remote branch, which is named 'origin/master'.
Process through the merge.
Commit any changes to your local repository.
Push your changes to the remote repository.
Go have a tasty beverage, congratulating yourself. Take the rest of the day off.
In my case I chose the Force Update checkbox while pushing. It worked like a charm.
In the meantime (while you were updating your project), other commits have been made to the 'master' branch. Therefore, you must pull those changes first to be able to push your changes.
Applicable for Eclipse Luna + Eclipse Git 3.6.1
I,
cloned git repository
made some changes in source code
staged changes from Git Staging View
finally, commit and Push!
And I faced this issue with EGit and here is how I fixed it..
Yes, someone committed the changes before I commit my changes. So the changes are rejected.
After this error, the changes gets actually committed to local repository.
I did not want to just Pull the changes because I wanted to maintain linear history as pointed out in - In what cases could `git pull` be harmful?
So, I executed following steps
from Git Repository perspective, right click on the concerned Git
project
select Fetch from Upstream - it fetches remote updates (refs and objects) but no updates are made locally. for more info refer What is the difference between 'git pull' and 'git fetch'?
select Rebase... - this open a popup, click on Preserve merges during rebase see why
What exactly does git's "rebase --preserve-merges" do (and why?)
click on Rebase button
if there is/are a conflict(s), go to step 6 else step 11
a Rebase Result popup would appear, just click on OK
file comparator would open up, you need to modify left side file.
once you are done with merging changes correctly, goto Git Staging view
stage the changes. i.e. add to index
on the same view, click on Rebase-> Continue. repeat 7 to 10 until all conflicts are resolved.
from History view, select your commit row and select Push Commit
select Rebase Commits of local....... checkbox and click next. refer why - Git: rebase onto development branch from upstream
click on Finish
Note: if you have multiple local repository commits, you need to squash them in one commit to avoid multiple merges.
Configure
After pushing the code when you get a rejected message, click on configure and click Add spec as shown in this picture
Drop down and click on the ref/heads/yourbranchname and click on Add Spec again
Make sure you select the force update
Finally save and push the code to the repo
Open git view :
1- select your project and choose merge
2- Select remote tracking
3- click ok
Git will merge the remote branch with local repository
4- then push
This error means that remote repository has had other commits and has paced ahead of your local branch.
I try doing a git pull followed by a git push. If their are No conflicting changes, git pull gets the latest code to my local branch while keeping my changes intact.
Then a git push pushes my changes to the master branch.
In my case i forgot to pull the new changes from git
Right click on the project Fetch From Upstream
Right click on the project Pull
Right click on the project Push to Upstream
I have found that you must be on the latest commit of the git.
So these are the steps to take:
1) make sure you have not been working on the same files, otherwise you will run into a DITY_WORK_TREE error.
2) pull the latest changes.
3) commit your updates.
Hope this helps.
Go in Github an create a repo for your new code.
Use the new https or ssh url in Eclise when you are doing the push to upstream;

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)