views:

112

answers:

3

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. So 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? Thanks Dan

+1  A: 

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.

MikeD
There might be something to this as several of the merge conflicts were due to unix newline formatting, although I'm only using windows computers.
Dan
The --ignore-space-at-eol option is only for git diff, how does this help me when merging?
Dan
Probably incorrectly, I thought that git merge automatically used git diff for some of the work. See edit for a more thoughts.
MikeD
Thanks for the link. To illuminate further, this is not a new repo and I've done several merges between these two computers and never had a problem. Like I said this should have been a very clean merge as there were no changes made on the office computer and only changes on my home computer over the weekend. But on Monday it got ugly.
Dan
+1  A: 

Hi,

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.

Ramkumar Ramachandra
+2  A: 

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...

Tobias Kienzler
Thanks for the link. I ran the commands on my office repo and didn't find any files to fix. But when I ran it on my home repo it did find several files where it replaced the crlf. I will keep it in mind before I merge the next time.
Dan
@Dan also remember to check for a consistent autocrlf setting
Tobias Kienzler