Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge: why do I get a lot of merge conflicts after modifying the source on both linux and windows?

I was doing some work at home over the weekend and used git to merge code changes back to my office computer (connected via a vpn) and found some very ugly merge problems.

First of all the merge should have been very clean as everything was committed at the office on Friday and I only made changes to my home computer on Saturday and Sunday. But when I pulled the changes to my office computer I ended up with a ton of merge conflicts.

I cleaned up the merge conflicts, but then I found that many of the files (from what I can tell any file that I changed over the weekend) had <<<<<<< HEAD" and ">>>>>>> D1/master throughout the files. For example:

diff --git a/web/Web.Controller/Helpers/FormsAuthentication.cs b/web/Web.Controller/Helpers/FormsAuthentication.cs
index 8571f53..4a9c9fc 100644
-- a/web/Web.Controller/Helpers/FormsAuthentication.cs
++ b/web/Web.Controller/Helpers/FormsAuthentication.cs
@@ -10,7 +10,10 @@
    /// </summary>
    public class FormsAuthenticationUtility : IAuthenticationUtility
    {
<<<<<<< HEAD

=======
>>>>>>> D1/master
        #region IAuthentication Members

        /// <summary>

I was able to fix the code using kdiff by comparing with the source code copied from my home computer, but this just seems completely messed up.

Any ideas what is going on?

like image 998
Dan Avatar asked Jun 28 '10 14:06

Dan


People also ask

Why are there so many merge conflicts?

Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. Make sure you both have clean branch to start. Whenever some have to push its commit, first stash their changes if present.


3 Answers

I encountered the same problem when Windows files where merged into my Linux repo, so that was a CRLF issue. I could finally fix that with the help of this answer. IIRC this had to be done before merging, but it's been a while and honestly I forgot to write it down...

like image 143
Tobias Kienzler Avatar answered Oct 22 '22 22:10

Tobias Kienzler


I've had a problem like this come up when going from Windows to *Nix and back due to their different treatment of newline characters. Git might be picking up on those differences and for whatever reason failing to merge.

Maybe try --ignore-space-at-eol?

Edit:

White space actually does matter when merging. It might not matter in your exact case, but there are contexts where it might make a difference. This question seems to address what should be done to resolve the conflicts much better than I ever could.

like image 45
MikeD Avatar answered Oct 22 '22 21:10

MikeD


This sounds like the CRLF problem while merging: it sparked off a recent discussion here. You might might also want to try to build a reduced case with a few files to find out what exactly is causing this problem.

like image 25
artagnon Avatar answered Oct 22 '22 22:10

artagnon