Git in Eclipse: How can I overwrite the changes on the repo? - eclipse

I am very new with git and repositorys and I have a problem. Me and my collegue were working on the same file.
He commited and pushed his changes.
I commited my changes
I pulled
Now I have conflicts and I want to solve them. How can I overwrite the conflicts so that my changes are on the file? I am working with Eclipse.

There is no easy way to resolve conflicts. But tools are available to make the process a little easier. Anyhow you will have to decide and manually make the changes so that both of your changes are available in the latest file.
Try: git mergetool
If you both edited separate parts of the file then the tool will automatically merge whereas if you both have edited the same part then some manual interaction is needed.

If you want Your changes you can use:
git fetch -p
git merge --ours
This will merge the remote with your local branches and in case of any conflict - use your version of code.

Related

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.

Failed, DIRTY_WORKTREE in eclipse, how to solve it?

I am currently working on a java project and when committing my changes and pulling I get the following error. I don't know how to resolve it:
I tried everything, but can't seem to fix the problem, can someone please help me?
To be clear, I am using eclipse.
Delete the affected files and try to pull again. Thereafter push your changes to the git.
below steps may help
delete non-versioned files
git clean -df
reset your local changes
git fetch
git reset --hard
I got the same error while trying to merge the code. Delete the respective file in either of the branches to merge
Assuming your working in a local branch, that is branched from a remote branch, and the merge conflict is occurring after you 'commit and push' upstream, merge to remote branch.
Try these 3 steps:
Copy off the new changes from the specific file causing the merge issue.
In Eclipse, Explorer pane, rt-click on the specific file causing the merge issue, and select replace with previous revision.
Now perform a 'commit and push'
Perform a merge to remote branch (no conflict should be observed).
In Eclipse, rt-click on the specific file again, and select 'pull' - the file should now be in sync all the way through.
Now add the new changes, save, commit and push, and merge to remote branch (not conflicts should be observed).
In my case, I had uncommitted changes.
I committed my changes and then I was able to merge successfully without dirty_worktree error.
So... another option that worked for me and my DIRTY_WORKTREE... Stash your changes and then Pull.
This solution meant that I did NOT lose some local useful logging changes from simply deleting the offending file.
I had the same error as:
DIRTY_WORKTREE pom.xml
So I deleted the pom.xml from my working directory and did a pull from particular branch.
It worked for me.
I resolved this error by selecting "Assume Unchanged" for the file that I was unable to delete.
STS, In the toolbar. Show View->Git Staging->Unstaged Changes.
OR
Right-click on the file->Team->Advanced->Assume Unchanged
The most simple and easy way is to Rebase
Right click Repo > Rebase
See image
Stash your changes
Done, WOW
From the stashed changes just compare and take necessary code or you can apply stash

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.

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

Mercurial workflow for updating with uncommitted changes?

So i've made the switch from CVS to mercurial for my website.
The biggest issue I am having is that if i'm working on some files that I don't want to commit, I just save them.. I then have other files I want to push to the server, however if someone else has made changes to the repository, and I pull them down.. It asks me to merge or rebase.. either of these options will cause me to lose my local changes that I have not committed.
I've read that I should clone the repository for each project on my local host and merge it into the live when it's ready to do so. This not only seems tedious, but also takes a long time as it's a large repository.
Are there better solutions to this?
I would have hoped that Mercurial would see that I haven't committed my changes (even though I have changed the file from what's on the server) so it'd just overlook the file.
Any input on this would be greatly appreciated. Thank you!
Also, i'm using the hg eclipse plugin to work on my files and push/pull from the server.
hg shelve is your friend here I think.
which comes from the shelve extention (maybe - see below)
from the overview:
The shelve extension provides the
shelve command to lets you choose
which parts of the changes in a
working directory you'd like to set
aside temporarily, at the granularity
of patch hunks. You can later restore
the shelved patch hunks using the
unshelve command.
The shelve extension has been adapted
from Mercurial's RecordExtension.
or maybe its the attic extension
This module deals with a set of
patches in the folder .hg/attic. At
any time you can shelve your current
working copy changes there or unshelve
a patch from the folder.
it seems to have the same syntax as the shelve extension, so I'm not certain which one I've used
I second #Sam's answer. However, if you prefer to use standard Mercurial, a simple workflow is to
save your working dir changes in a temporary file,
sync your working dir with a specific revision, then
push, pull, merge .. whatever you want to do and which requires a clean working copy, and
get back your changes from the temporary file into the working dir.
For instance:
$ hg diff > snapshot.patch # save your uncommited changes
$ hg up -C # get a clean working copy
$ hg pull # do things ..
$ hg merge # .. you need a clean ..
$ hg commit -m "merge" # .. working copy for
$ hg import snapshot.patch # get back your uncommited work
First, are you working from the commandline, or using something like Tortoise?
If you're working from the commandline, and you've done a pull, mercurial will not ask you to do anything, as it merely updates your local repository.
If you then do an hg update and have local changes, it should do what you're used to from CVS. It will update to the tip of the current branch, and attempt to merge your outstanding changes in. There are some caveats to that, so refer to the official docs at http://www.selenic.com/mercurial/hg.1.html#update.
Also, for temporarily storing changes, I would recommend MQ over shelve. Shelve only provides one storage area, whereas MQ provides as many as you need. MQ takes some getting used to, but worth the investment.