How do I merge a binary file?

前端 未结 2 550
你的背包
你的背包 2021-02-07 10:45

I have a binary file in my_branch, and when I need to make changes to it, git will of course not merge it.

So what I do now is:

git checkout my_branch
#          


        
2条回答
  •  别跟我提以往
    2021-02-07 11:17

    you could use the built-in binary merge driver:

    binary: Keep the version from your branch in the work tree, but
    leave the path in the conflicted state for the user to sort out.
    

    example .gitattributes line:

    *.bin -crlf -diff merge=binary
    

    tells git not to add line endings, not to diff, and to keep the local version

    http://git-scm.com/docs/gitattributes

    that only preserves your working copy...

    another way is to use a custom merge driver:

    [merge "binmerge"]
      name = my binary merge script
      driver = binmerge.sh %O %A %B
    

    That could check the conflicting file against a list of files that should always be overwritten by your local version...

    to use a merge driver, define it in the config, then specify what paths it should be used on in .gitattributes, like so:

    *.bin -crlf -diff merge=binmerge
    

    binmerge.sh will be called to handle the merge. it can essentially just do something like:

    #!/bin/sh
    echo "Performing merge of binary object ($1, $2, $3)"
    touch $2
    exit 0
    

提交回复
热议问题