tags:

views:

85

answers:

2

Is there a simple way to handle binary files in git operations? I think my ideal in this case - 'merging' of .mo files (binary .po messages) - would be to give precedence to the newer file, copying it over the top of the older one.

So can I configure git to do this or is it always going to be a manual exercise?

A: 

Well the best idea is not to keep generated files (such as .mo files) under version control.

If you still want to have them in Git, use standard ways to resolve conflicts.

For example you can get either version of conflicting file:

git checkout --theirs -- dir/file.mo
git checkout --ours -- dir/file.mo

Or use git mergetool which will provide you both versions of conflicting file.

Michal Čihař
Not really what I'm looking for - every morning I merge my changes with my colleague's. If he has added or (re)defined messages, I want to pick them up without having to regenerate the mo file locally. Of course, if we have both made message changes, then I'd have to regenerate, but that happens as often as solar eclipses. What I want is for git to copy the latest file without asking questions - a kind of an ignore directive that blindly copies rather than ignores.
Leo
But if only one changes the messages, there should be no conflict at all.
Michal Čihař
+1  A: 

You could add a custom merge driver in a gitattributes file (see this SO question), only for the *.mo files and only in the relevant directories.

echo *.mo merge=keepTheir > dirWithMoFiles\.gitattributes
git config merge.keepTheir.name "always keep theirduring merge"
git config merge.keepTheir.driver "keepTheir.sh %O %A %B"

With keepTheir.sh as:

mv -f $3 $2
exit 0
VonC
This looks like an interesting possibility. I'll investigate later when I've finished what I'm doing now.
Leo