{"thread":{"id":"17866","subject":"Retry conflicting merge with matching line endings?","startedAt":"2009-02-18T01:55:42Z","lastAt":"2009-02-18T03:44:40Z","messageCount":3,"participants":["skillzero@gmail.com","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"105258","messageId":"2729632a0902171755n3e89e717p6b3a38b556252bfb@mail.gmail.com","threadId":"17866","inReplyTo":null,"subject":"Retry conflicting merge with matching line endings?","fromName":"","fromEmail":"skillzero@gmail.com","sentAt":"2009-02-18T01:55:42Z","receivedAt":"2009-02-18T01:55:42Z","isPatch":false,"sender":{"key":"skillzero@gmail.com","avatar":null},"body":"I've been running into a lot of merge conflicts due to line endings\nchanging. For example, I branch from master when a file has CRLF line\nendings (incorrectly) then somebody fixes a bug in that file (still\nhas CRLF line endings) on master then I realize the file should have\nLF line endings so I change them. When I try to rebase on master\nlater, I get a merge conflict because it looks like every line has\nchanged and it conflicts with that other bug fix.\n\nWould it be reasonable that if you get a conflict during a merge and\nthe line endings of the two commits are different then change the line\nendings to match, retry the merge of that file, then apply the line\nending change commit?\n"},{"id":"105261","messageId":"7v8wo41o8d.fsf@gitster.siamese.dyndns.org","threadId":"17866","inReplyTo":"2729632a0902171755n3e89e717p6b3a38b556252bfb@mail.gmail.com","subject":"Re: Retry conflicting merge with matching line endings?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-02-18T02:18:58Z","receivedAt":"2009-02-18T02:18:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"skillzero@gmail.com writes:\n\n> I've been running into a lot of merge conflicts due to line endings\n> changing. For example, I branch from master when a file has CRLF line\n> endings (incorrectly) then somebody fixes a bug in that file (still\n> has CRLF line endings) on master then I realize the file should have\n> LF line endings so I change them. When I try to rebase on master\n> later, I get a merge conflict because it looks like every line has\n> changed and it conflicts with that other bug fix.\n>\n> Would it be reasonable that if you get a conflict during a merge and\n> the line endings of the two commits are different then change the line\n> endings to match, retry the merge of that file, then apply the line\n> ending change commit?\n\nThis is not specific to fixing line ending but applies any \"global token\nreplacement\" (e.g. you renamed a variable) operation in general.\n\nSuppose the conflicted path is hello.c when you were merging branch\n\"other\", e.g. \n\n\t$ git merge other\n\t$ git ls-files -u\n        100644 b040a96e50... 1\thello.c\t\n\t100644 6b9c715d21... 2\thello.c\n\t100644 1c57d4c958... 3\thello.c\n\nYou can first extract the blobs involved into plain files, apply such\n\"global token replacement\" (be it fixing the line ending or renaming a\nvariable) to the common ancestor version and the other's version, and run\nthree-way file-level merge.\n\n\t$ git cat-file blob :1:hello.c | replacement_filter >ancestor\n        $ git cat-file blob :2:hello.c >mine\n        $ git cat-file blob :3:hello.c | replacement_filter >theirs\n\t$ git merge-file mine ancestor theirs\n\nwhere replacement_filter would be whatever global replacement you did to\nyour version since the ancestor (e.g. dos2unix).\n\nThe \"mine\" file merge-file leaves will hopefully have much smaller\nconflicts, as it won't have to see your line endings change.  If it looks\nOk, cat it into hello.c and \"git add\" it.\n"},{"id":"105268","messageId":"2729632a0902171944l7a5ca5b4nf6d77bc7f9c1b201@mail.gmail.com","threadId":"17866","inReplyTo":"7v8wo41o8d.fsf@gitster.siamese.dyndns.org","subject":"Re: Retry conflicting merge with matching line endings?","fromName":"","fromEmail":"skillzero@gmail.com","sentAt":"2009-02-18T03:44:40Z","receivedAt":"2009-02-18T03:44:40Z","isPatch":false,"sender":{"key":"skillzero@gmail.com","avatar":null},"body":"On Tue, Feb 17, 2009 at 6:18 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>\n> This is not specific to fixing line ending but applies any \"global token\n> replacement\" (e.g. you renamed a variable) operation in general.\n\nThanks for the details. I was previously resolving things in a more\ntedious manner and your steps will make things easier for me.\n\nWhat I was curious about though is whether it would be reasonable for\nme to submit a patch to have git automatically try this for the\nspecial case of line endings (possibly implemented as a general token\nreplacement scheme with built-in filters for line endings)?\n"}]}