Search code examples
gitbinarymo

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


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?


Solution

  • 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