I used git pull
and had a merge conflict:
unmerged: _widget.html.erb
You are in the middle of a conflicted merge.
I know that the other version of the file is good and that mine is bad so all my changes should be abandoned. How can I do this?
An alternative, which preserves the state of the working copy is:
I generally advise against this, because it is effectively like merging in Subversion as it throws away the branch relationships in the following commit.
In this particular use case, you don't really want to abort the merge, just resolve the conflict in a particular way.
There is no particular need to reset and perform a merge with a different strategy, either. The conflicts have been correctly highlighted by git and the requirement to accept the other sides changes is only for this one file.
For an unmerged file in a conflict git makes available the common base, local and remote versions of the file in the index. (This is where they are read from for use in a 3-way diff tool by
git mergetool
.) You can usegit show
to view them.The simplest way to resolve the conflict to use the remote version verbatim is:
Or, with git >= 1.6.1:
I think it's
git reset
you need.Beware that
git revert
means something very different to, say,svn revert
- in Subversion the revert will discard your (uncommitted) changes, returning the file to the current version from the repository, whereasgit revert
"undoes" a commit.git reset
should do the equivalent ofsvn revert
, that is, discard your unwanted changes.And if you end up with merge conflict and doesn't have any things to commit but still merge error is being displayed after applying all the below mentioned commands,
please remove
file [cut paste to some other location in case of recovery] and then enter any of below command depending on which version you want.
Hope that helps!!!
http://www.git-scm.com/docs/git-merge