{"thread":{"id":"12580","subject":"Can git be stopped from inserting conflict markers during a merge?","startedAt":"2008-03-08T17:55:47Z","lastAt":"2008-03-08T22:24:21Z","messageCount":4,"participants":["William Tanksley","Linus Torvalds","Jakub Narebski","Martin Langhoff"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"71434","messageId":"loom.20080308T174918-559@post.gmane.org","threadId":"12580","inReplyTo":null,"subject":"Can git be stopped from inserting conflict markers during a merge?","fromName":"William Tanksley","fromEmail":"wtanksleyjr+git@gmail.com","sentAt":"2008-03-08T17:55:47Z","receivedAt":"2008-03-08T17:55:47Z","isPatch":false,"sender":{"key":"wtanksleyjr+git@gmail.com","avatar":null},"body":"I started using Mercurial a while ago, and I'd like to move up to git (for a\nnumber of reasons). The one thing that's stopping me is that (having recently\nescaped subversion and cvs) I'm now used to NOT having to worry about conflict\nmarkers being shoved into files. To put it simply, I really like how Mercurial\ndoes that one thing.\n\nSo, given the git is probably the ultimate in configurability, what do I need to\ndo to make it not insert merge markers?\n\nThanks for a great VCS.\n\n-Wm\n\n"},{"id":"71440","messageId":"alpine.LFD.1.00.0803081242040.5896@woody.linux-foundation.org","threadId":"12580","inReplyTo":"loom.20080308T174918-559@post.gmane.org","subject":"Re: Can git be stopped from inserting conflict markers during a merge?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2008-03-08T20:51:40Z","receivedAt":"2008-03-08T20:51:40Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sat, 8 Mar 2008, William Tanksley wrote:\n>\n> I started using Mercurial a while ago, and I'd like to move up to git (for a\n> number of reasons). The one thing that's stopping me is that (having recently\n> escaped subversion and cvs) I'm now used to NOT having to worry about conflict\n> markers being shoved into files. To put it simply, I really like how Mercurial\n> does that one thing.\n\nCan you describe what \"that one thing\" is?\n\n> So, given the git is probably the ultimate in configurability, what do I need to\n> do to make it not insert merge markers?\n\nDo you want to just have both (with the base version, all three?) versions \nof the file in your directory?\n\nThat's actually conceptually what you have with git, even though what git \ndoes is to keep the different untouched versions in the index. So with \ngit, you actually have *four* different versions of a file when you have a \nconflict:\n\n - the working tree one (which has the conflict markers, because that's \n   traditional)\n - and index stages 1 (base) 2 (ours) and 3 (theirs)\n\nwhich is why when you do\n\n\tgit diff\n\non an unmerged file, you actually get something much more powerful than \njust the conflict entries - you get a git multi-version diff. It's \n*really* convenient when you get used to it, but I you actually seem to be \nwanting something much simpler.\n\n\t\t\tLinus\n"},{"id":"71441","messageId":"m3ve3xexnw.fsf@localhost.localdomain","threadId":"12580","inReplyTo":"loom.20080308T174918-559@post.gmane.org","subject":"Re: Can git be stopped from inserting conflict markers during a merge?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-03-08T21:03:18Z","receivedAt":"2008-03-08T21:03:18Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"William Tanksley <wtanksleyjr+git@gmail.com> writes:\n\n> I started using Mercurial a while ago, and I'd like to move up to\n> git (for a number of reasons). The one thing that's stopping me is\n> that (having recently escaped Subversion and CVS) I'm now used to\n> NOT having to worry about conflict markers being shoved into\n> files. To put it simply, I really like how Mercurial does that one\n> thing.\n> \n> So, given the Git is probably the ultimate in configurability, what\n> do I need to do to make it not insert merge markers?\n\nFirst, if you simply enable installed by default (but not enabled)\npre-commit hook, by making it executable:\n\n  $ chmod a+x .git/hooks/pre-commit\n\nit would detect merge markers in changes, and would prevent committing\nwith \"unresolved merge conflict (line <n>)\" message[*1*].\n\nYou can of course bypass pre-comit and commit-msg hooks with\n--no-verify option, for example if committing merge test case, or if\nhooks misdetects asciidoc markup for merge conflict markers.\n\n\nSecond, you can change default file-level (file contents) merge driver\nto the one used for binary files; it would leave 'ours' version on\ndisk instead of merged file with merge conflict markers[*2*][*3*] \n\nSimply add the following to the repository configuration in\n'.git/config', or to global (user) git configuration in\n'~/.gitconfig', or if you are admin you can even add it to system wide\ngit config '/etc/gitconfig' although I wouldn't recommend last one:\n\n   [merge]\n   \tdefault = binary\n\nOr if you prefer scripted solution,\n\n  $ git config merge.default binary\n\n(this would change repository config: read git-config(1)).\n\n\nFootnotes:\n==========\n[*1*] It also detects \"trailing whitespace\" and \"indent SP followed by\n      a TAB\" errors; whitespace errors can be detected by git-commit\n      iself with --cleanup=<mode> option and/or gitattributes.\n[*2*] Sample session below:\n\n[master!test]$ git version\ngit version 1.5.4.2\n[master!test]$ git show master:foo\nHELLO\nhello\n[master!test]$ git show side:foo\nHELLO\nhello side\n[master!test]$ git merge side\nAuto-merged foo                           # [*4*]\nCONFLICT (content): Merge conflict in foo\nAutomatic merge failed; fix conflicts and then commit the result.\n[master!test]$ cat foo \nHELLO\n<<<<<<< HEAD:foo\nhello\n=======\nhello side\n>>>>>>> side:foo\n[master!test]$ git reset --hard HEAD\n[master!test]$ git config merge.default binary\n[master!test]$ git merge side\nAuto-merged foo\nCONFLICT (content): Merge conflict in foo\nAutomatic merge failed; fix conflicts and then commit the result.\n[master!test]$ cat foo \nHELLO\nhello\n\n[*3*] If you want to do this only for some files, you can use\n      gitattributes feature.\n[*4*] I wonder about this \"Auto-merged foo\" message...\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"71451","messageId":"46a038f90803081424s1a0091c6r4d9e24c62ef2bdd1@mail.gmail.com","threadId":"12580","inReplyTo":"alpine.LFD.1.00.0803081242040.5896@woody.linux-foundation.org","subject":"Re: Can git be stopped from inserting conflict markers during a merge?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2008-03-08T22:24:21Z","receivedAt":"2008-03-08T22:24:21Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On Sun, Mar 9, 2008 at 9:51 AM, Linus Torvalds\n<torvalds@linux-foundation.org> wrote:\n>  Do you want to just have both (with the base version, all three?) versions\n>  of the file in your directory?\n\nIf that's what he is after, git-mergetool will do it - normally as a\npreparation to call xxdiff or something similar. William, perhaps\ngit-mergetool is what you are after? You can look at the source --\nit's shell -- if you want to tweak it.\n\nBut I think that what mercurial does is similar to Arch and Bazaar\nbehaviour: it will update the file following \"one side\" of the merge,\nand then generate a .rej file with the unapplied hunks coming from the\n'other side'.  This selection is arbitrary, and doesn't work on\noctopus merges, so I end up not quite liking it. OTOH, if you open the\n.rej file with emacs in diff mode, it's bloody useful for fixing up\npatches so that they apply.\n\ncheers,\n\n\n\n\nm\n"}]}