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

2020-03-05 02:25发布

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?

标签: git binary mo
3条回答
倾城 Initia
2楼-- · 2020-03-05 02:47

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.

查看更多
做自己的国王
3楼-- · 2020-03-05 02:50

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)

查看更多
冷血范
4楼-- · 2020-03-05 03:05

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
查看更多
登录 后发表回答