Re: Can git be stopped from inserting conflict markers during a merge?
- From
Jakub Narebski <jnareb@gmail.com>
- Date
- Mar 8, 2008, 21:03 UTC
- Message-ID
- <m3ve3xexnw.fsf@localhost.localdomain>
- In-Reply-To
- <loom.20080308T174918-559@post.gmane.org>
William Tanksley <wtanksleyjr+git@gmail.com> writes:
Show 9 quoted lines
> I started using Mercurial a while ago, and I'd like to move up to > git (for a number of reasons). The one thing that's stopping me is > that (having recently escaped Subversion and CVS) I'm now used to > NOT having to worry about conflict markers being shoved into > files. To put it simply, I really like how Mercurial does that one > thing. > > So, given the Git is probably the ultimate in configurability, what > do I need to do to make it not insert merge markers?
First, if you simply enable installed by default (but not enabled) pre-commit hook, by making it executable:
$ chmod a+x .git/hooks/pre-commit
it would detect merge markers in changes, and would prevent committing with "unresolved merge conflict (line <n>)" message[*1*].
You can of course bypass pre-comit and commit-msg hooks with --no-verify option, for example if committing merge test case, or if hooks misdetects asciidoc markup for merge conflict markers.
Second, you can change default file-level (file contents) merge driver to the one used for binary files; it would leave 'ours' version on disk instead of merged file with merge conflict markers[*2*][*3*]
Simply add the following to the repository configuration in '.git/config', or to global (user) git configuration in '~/.gitconfig', or if you are admin you can even add it to system wide git config '/etc/gitconfig' although I wouldn't recommend last one:
[merge] default = binary
Or if you prefer scripted solution,
$ git config merge.default binary
(this would change repository config: read git-config(1)).
Footnotes:
==========
[*1*] It also detects "trailing whitespace" and "indent SP followed by
a TAB" errors; whitespace errors can be detected by git-commit
iself with --cleanup=<mode> option and/or gitattributes.
[*2*] Sample session below:[master!test]$ git version git version 1.5.4.2 [master!test]$ git show master:foo HELLO hello [master!test]$ git show side:foo HELLO hello side [master!test]$ git merge side Auto-merged foo # [*4*] CONFLICT (content): Merge conflict in foo Automatic merge failed; fix conflicts and then commit the result. [master!test]$ cat foo HELLO <<<<<<< HEAD:foo hello ======= hello side
>>>>>>> side:foo
[master!test]$ git reset --hard HEAD [master!test]$ git config merge.default binary [master!test]$ git merge side Auto-merged foo CONFLICT (content): Merge conflict in foo Automatic merge failed; fix conflicts and then commit the result. [master!test]$ cat foo HELLO hello
[*3*] If you want to do this only for some files, you can use
gitattributes feature.
[*4*] I wonder about this "Auto-merged foo" message...-- Jakub Narebski Poland ShadeHawk on #git