how to handle gitting of binaries, e.g. .mo files
Asked Answered
S

3

3

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?

Susannesusceptibility answered 9/3, 2010 at 11:55 Comment(0)
G
4

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
Grained answered 9/3, 2010 at 12:25 Comment(1)
This looks like an interesting possibility. I'll investigate later when I've finished what I'm doing now.Susannesusceptibility
B
0

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.

Bonner answered 9/3, 2010 at 12:12 Comment(2)
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.Susannesusceptibility
But if only one changes the messages, there should be no conflict at all.Semiaquatic
R
0

basically this concept was nicely explain here How do I tell git to always select my local version for conflicted merges on a specific file?

and here is a bash script simplifying the steps described there https://github.com/equivalent/git_to_svn_behavior-

(steps how to run in Readme)

Rattlebrain answered 24/8, 2011 at 17:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.