Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell git not to merge binary files but to choose

When the binary files, swfs, jars and flvs are changed locally, and I try to pull in changes, git tries to merge them and reports conflict.

And then, I branch to a temporary branch, and commit the local changed binary files, and merge them back after the pull with recursive theirs strategy. -- Too much work.

Is there a way to tell git, not to attempt merging binary files and ask me which one of these versions to use.

like image 420
lprsd Avatar asked May 27 '10 11:05

lprsd


People also ask

How do you stop git from merging?

How do I cancel a git merge? Use git-reset or git merge --abort to cancel a merge that had conflicts. Please note that all the changes will be reset, and this operation cannot be reverted, so make sure to commit or git-stash all your changes before you start a merge.

How does git decide to merge?

Instead, Git uses an algorithm to determine what bits of a file have changed and if any of those bits could represent a conflict. For simple text files, Git uses an approach known as the longest common subsequence algorithm to perform merges and to detect merge conflicts.

Does git work with binary files?

Git LFS is a Git extension used to manage large files and binary files in a separate Git repository. Most projects today have both code and binary assets. And storing large binary files in Git repositories can be a bottleneck for Git users. That's why some Git users add Git Large File Storage (LFS).


1 Answers

You could set up a merge drive in a .gitattributes file (only for a given subtree, only for some file types)

See this question for instance (or this one).

# choose the name of the merge driver to be use for all jar files
echo *.jar merge=keepTheir > dirWithJarFiles\.gitattributes

Declare your merge driver in the config of the Git repo:

git config merge.keepTheir.name "always keep their during merge"
git config merge.keepTheir.driver "keepTheir.sh %O %A %B"

or

git config merge.keepMine.name "always keep mine during merge"
git config merge.keepMine.driver "keepMine.sh %O %A %B"
[merge "keepMine"]
        name = always keep mine during merge
        driver = keepMine.sh %O %A %B

The example I give don't ask you for a choice but will always keep "mine" (or "yours") version when merging.
But you could adapt the script executed by this merge driver to ask you a question, and then apply your choice to all merges.

like image 170
VonC Avatar answered Sep 23 '22 19:09

VonC