threads / discuss / 29908

Trouble with file specific merge strategies

Subject: Trouble with file specific merge strategies

## tl;dr

7 messages between Mar 10, 2012 and Mar 11, 2012.

replies: 6people: 3as markdown or json

suvayu ali· Mar 10, 2012, 23:47 UTC · lore
Hi git devs,

I have a repo with two branches where some files are absent in one of the branches. Say the two branches are <allfiles> and <somefiles>. Until now I was using

$ git merge -s ours <allfiles> # with <somefiles> checked out

to merge commits which touches the absent files. But this clutters up history and is very inconvenient to do sometimes. So when I came across the possibility of using .gitattributes for file specific merge strategies, I tried the following:

pattern merge=ours
However I get the following conflict message:

CONFLICT (rename/delete): org-mode-config.el deleted in HEAD and renamed in 74288bb. Version 74288bb of org-mode-config.el left in tree.

This file was deleted from <somefiles> in the past[1] and was renamed in <allfiles> since the last merge. I was expecting this file to be ignored (or in other words, merged with ours) since the .gitattributes file has entries like these:

org-mode-config.el merge=ours # new name in allfiles branch lisp/org-mode-settings.el merge=ours # old name deleted in somefiles

I also see other new files in <allfiles> which are mentioned in .gitattributes being merged in <somefiles>.

$ git status -sb ## somefiles M abbrev_defs A cpp-config.el A email-config.el # <-- this should be ignored A gui-config.el # <-- this should be ignored UU init.el A keybindings.el M lisp/skeletons.el D lisp/text-mode-like-settings.el UA org-mode-config.el # <-- this should be ignored A text-mode-config.el

What am I doing wrong here? My git version is 1.7.7.6.
Thanks in advance,
Footnotes:
[1] There has been several successful merges since then.
-- 
Suvayu

Open source is the future. It sets us free.
Junio C Hamano· Mar 11, 2012, 08:57 UTC · re: suvayu ali · lore

Re: Trouble with file specific merge strategies

suvayu ali <fatkasuvayu+linux@gmail.com> writes:
Show 5 quoted lines
> ... So when I came across
> the possibility of using .gitattributes for file specific merge
> strategies, I tried the following:
>
> pattern merge=ours

I do not think we say .gitattributes can give merge strategy anywhere in our document.

You can choose one of the few built-in merge drivers but "ours" is not one of them. Have you defined your own merge driver "ours" following the example in the gitattributes documentation (look for "feel-free merge driver")?

suvayu ali· Mar 11, 2012, 10:10 UTC · re: Junio C Hamano · lore

Re: Trouble with file specific merge strategies

Hi Junio,
On Sun, Mar 11, 2012 at 09:57, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> suvayu ali <fatkasuvayu+linux@gmail.com> writes:
>
>> ... So when I came across
>> the possibility of using .gitattributes for file specific merge
>> strategies, I tried the following:
>>
>> pattern merge=ours
>
> I do not think we say .gitattributes can give merge strategy
> anywhere in our document.
>
> You can choose one of the few built-in merge drivers but "ours" is
> not one of them.  Have you defined your own merge driver "ours"
> following the example in the gitattributes documentation (look for
> "feel-free merge driver")?

Ah, that explains it. You are absolutely correct in saying that the docs don't imply this. I was having doubts about this while reading the docs (man gitattributes). I got confused by this[1] example on progit and several pointers to it on stackoverflow. And no, I don't have a custom merge driver.

This brings up the question, is that discussion on progit talking about something else? Is there a way to setup file specific merge strategies in a repo?

Thanks a lot for your response. :)
Cheers,
Footnotes:
[1] http://progit.org/book/ch7-2.html#merge_strategies
-- 
Suvayu

Open source is the future. It sets us free.
Junio C Hamano· Mar 11, 2012, 11:18 UTC · re: suvayu ali · lore

Re: Trouble with file specific merge strategies

suvayu ali <fatkasuvayu+linux@gmail.com> writes:
> ... is that discussion on progit talking about
> something else?

Sorry, I do not read or write progit, so I do not know offhand what it says in the section you read and I cannot judge if it was you who misread, or if it was book that misspoke.

suvayu ali· Mar 11, 2012, 11:27 UTC · re: Junio C Hamano · lore

Re: Trouble with file specific merge strategies

Hi Junio,
On Sun, Mar 11, 2012 at 12:18, Junio C Hamano <gitster@pobox.com> wrote:
Show 9 quoted lines
> suvayu ali <fatkasuvayu+linux@gmail.com> writes:
>
>> ... is that discussion on progit talking about
>> something else?
>
> Sorry, I do not read or write progit, so I do not know offhand what
> it says in the section you read and I cannot judge if it was you who
> misread, or if it was book that misspoke.
>
Okay, thanks. I'll switch back to the tried and tested,
$ git merge -s ours
I'll take up the progit issue on the relevant discussion boards.
-- 
Suvayu

Open source is the future. It sets us free.
Thomas Hochstein· Mar 11, 2012, 15:17 UTC · re: Junio C Hamano · lore

Re: Trouble with file specific merge strategies

Junio C Hamano wrote:
Show 8 quoted lines
> suvayu ali <fatkasuvayu+linux@gmail.com> writes:
>
>> ... is that discussion on progit talking about
>> something else?
>
> Sorry, I do not read or write progit, so I do not know offhand what
> it says in the section you read and I cannot judge if it was you who
> misread, or if it was book that misspoke.
The book says:
Show 23 quoted lines
> You can also use Git attributes to tell Git to use different merge
> strategies for specific files in your project. One very useful option
> is to tell Git to not try to merge specific files when they have
> conflicts, but rather to use your side of the merge over someone
> else’s.
>
> This is helpful if a branch in your project has diverged or is
> specialized, but you want to be able to merge changes back in from
> it, and you want to ignore certain files. Say you have a database
> settings file called database.xml that is different in two branches,
> and you want to merge in your other branch without messing up the
> database file. You can set up an attribute like this:
>
>| database.xml merge=ours
>
> If you merge in the other branch, instead of having merge conflicts
> with the database.xml file, you see something like this:
>
>| $ git merge topic
>| Auto-merging database.xml
>| Merge made by recursive.
>
> In this case, database.xml stays at whatever version you originally had.

That seems to be incorrect, as far as I understand the gitattributes man page.

-thh
suvayu ali· Mar 11, 2012, 18:01 UTC · re: Thomas Hochstein · lore

Re: Trouble with file specific merge strategies

Hello Thomas,
On Sun, Mar 11, 2012 at 16:17, Thomas Hochstein <thh@inter.net> wrote:
Show 39 quoted lines
> Junio C Hamano wrote:
>
>> suvayu ali <fatkasuvayu+linux@gmail.com> writes:
>>
>>> ... is that discussion on progit talking about
>>> something else?
>>
>> Sorry, I do not read or write progit, so I do not know offhand what
>> it says in the section you read and I cannot judge if it was you who
>> misread, or if it was book that misspoke.
>
> The book says:
>> You can also use Git attributes to tell Git to use different merge
>> strategies for specific files in your project. One very useful option
>> is to tell Git to not try to merge specific files when they have
>> conflicts, but rather to use your side of the merge over someone
>> else’s.
>>
>> This is helpful if a branch in your project has diverged or is
>> specialized, but you want to be able to merge changes back in from
>> it, and you want to ignore certain files. Say you have a database
>> settings file called database.xml that is different in two branches,
>> and you want to merge in your other branch without messing up the
>> database file. You can set up an attribute like this:
>>
>>| database.xml merge=ours
>>
>> If you merge in the other branch, instead of having merge conflicts
>> with the database.xml file, you see something like this:
>>
>>| $ git merge topic
>>| Auto-merging database.xml
>>| Merge made by recursive.
>>
>> In this case, database.xml stays at whatever version you originally had.
>
> That seems to be incorrect, as far as I understand the gitattributes
> man page.
>

Thank you for confirming the error. I have opened a ticket on the progit repo on github. If you are interested, you can follow it on the page linked below.

<https://github.com/progit/progit.github.com/issues/5>
Cheers,
-- 
Suvayu

Open source is the future. It sets us free.

← back to recent threads