Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve ALL conflicts using HEAD, with any mergetool

So for some reason I'm getting a lot of conflicts with a new merged hotfix. The file that was actually [manually] changed has no conflict. All the conflicts are in files that were untouched during the fix and apparently its an issue with whitespaces. I'll try to figure that problem later but now I need to merge the hotfix and deploy.

How can I resolve ALL conflicts to use the HEAD version? I don't want to go file by file. Yes, I know its a bad practice but the conflicts are all whitespaces and I know HEAD is correct — passing all tests and running fine in production.

Any ideas?

I'm using OSX.

like image 492
leonsas Avatar asked Nov 26 '13 22:11

leonsas


People also ask

How do I use git Mergetool to resolve conflicts?

Concepts for resolving Git conflictsREMOTE - the head for files(s) from a remote location that you are trying to merge into your LOCAL branch. BASE - the common ancestor(s) of LOCAL and REMOTE . MERGED - the tag / HEAD object after the merge - this is saved as a new commit.

Which command is used after resolving all merge conflicts?

The traditional way of completing a merge after resolving conflicts is to use ' git commit '.


2 Answers

git merge -Xours origin/master 

will do a merge with origin/master (the same thing that git pull origin master does) and will resolve any conflicts by taking the versions from your local branch.

If you're already part-way through the bad merge, you can reset everything to the head first with git reset --hard HEAD.

In that case, you should do

git reset --hard HEAD git merge -Xours origin/master 

And that should fix your problem!

(also worth mentioning, -Xtheirs will do the same thing, but take the upstream version in any conflicts.)


Also, most likely the conflicts are because the upstream version is using windows-style line endings, and whatever program you edited the files in on your local machine is using mac-style or linux-style line endings.

There are options you can set in git to always commit windows-style or linux-style line endings, but always checkout mac-style or linux-style in your working directory.

See this link for more info: https://help.github.com/articles/dealing-with-line-endings

like image 166
NHDaly Avatar answered Sep 22 '22 19:09

NHDaly


If you have conflict on your local branch you can simply run these commands:

git checkout --conflict=merge . git checkout --ours . 

To solve conflicts using your local branch.

like image 29
Yametekudasai Avatar answered Sep 25 '22 19:09

Yametekudasai