Reputation: 210360
In Git, is it possible to change the default conflict markers to something else?
By default they look like this:
<<<<<<< HEAD
[some code]
||||||| merged common ancestors
[some code]
=======
[some code]
>>>>>>> some commit message
For instance, I was thinking it might be nice in C# files to have them start with comment characters:
// <<<<<<< HEAD
That way compile errors from the conflict markers wouldn't get in the way of compile errors from the code itself while I'm resolving a merge.
Is there a way to do this?
(Please don't give an answer that says "You shouldn't do this." I already know the ramifications, and I'm OK with them. Git is designed for flexibility.)
Upvotes: 0
Views: 387
Reputation: 15756
It's up to the individual merge driver. From man gitattributes(5):
There are a few built-in low-level merge drivers defined that can be asked for via the merge attribute.
text
Usual 3-way file level merge for text files. Conflicted regions are marked with conflict markers <<<<<<<, ======= and >>>>>>>. The version from your branch appears before the ======= marker, and the version from the merged branch appears after the ======= marker.
[…]
Defining a custom merge driver
The definition of a merge driver is done in the .git/config file, not in the gitattributes file, so strictly speaking this manual page is a wrong place to talk about it. However…
To define a custom merge driver filfre, add a section to your $GIT_DIR/config file (or $HOME/.gitconfig file) like this:
[merge "filfre"]
name = feel-free merge driver
driver = filfre %O %A %B
recursive = binary
That is: the "text" merge driver does what you don't like, and cannot be configured as to what symbol to use (though you can configure it to use a bigger number of markers). But you can copy-paste the driver, rename it, replace the symbol with yours, and then configure git to use your driver.
Upvotes: 0
Reputation: 129744
Here is how I would do it IF I HAD TO (proceed with caution):
add a precompile step in your projects (from your profile I assume you are using C#) to run sed (assuming you installed git with the bash commands available to everything). Have sed insert '//' markers where ever a conflict marker is found.
Why this is a bad idea:
I would not recommend this as the effect wouldn't give you any gain. You WANT to fail spectacularly when there is an unresolved conflict that was saved, added and committed. Doing what you are proposing here is asking for trouble. If you succeed, proceed with caution.
Hope this helps.
Upvotes: 1
Reputation: 49128
There's no existing way to do this. Git is indeed designed for flexibility, but in this instance it provides that flexibility by allowing people to provide their own custom merge drivers. That's not a trivial amount of work. Another option is to hack the source, which would not be much easier.
My recommendation for the easiest way would be to write a postprocessor program you can run on the source files separately after the merge. You could probably fit it in a one-liner sed script.
If you decide to go this route so you can compile during merge resolution, I would recommend instead of just commenting out the conflict markers, to comment out all the conflicted code except your local version of the changes. That way you have a better chance of producing something compilable. And maybe add a #warning pragma or similar to remind you in case you accidentally leave one in.
Upvotes: 0
Reputation: 5334
What if you recompile your own fork of Git? The source code is here: http://git.kernel.org/?p=git/git.git;a=summary (via http://git-scm.com/).
Upvotes: 1