iamcootis
iamcootis

Reputation: 2313

Is there a way to make large git objects binaries that do not attempt to merge?

I have a very large file which is essentially a .json file, but it's a format from a third-party. I always want the latest file to completely overwrite the current file. No merging, etc. This always becomes a headache when I attempt to rebase and I have a merge issue for each commit because of this file.

I thought setting up it's extension as an lfs would fix the issue, but it did not. Is there some way to set up git so that these types of files always accept the latest and never attempt to merge?

Upvotes: 0

Views: 40

Answers (2)

LeGEC
LeGEC

Reputation: 51850

You can set up a specific merge driver to merge that file.

This repo on github gives an illustration of how you can set one up,
and here is a link to the docs :

  1. write a script (merge-the-file.py for example), which takes two file names in argument, and overwrites the first file with "the version that should be kept",
  2. in your configuration, define a merge driver :
[merge "merge-that-file"]
    name = Merge the json file at the root of our repo
    driver = path/to/merge-the-file.py %A %B
  1. in the .gitattributes file in your repo, name that driver for that file :
# .gitattributes :
that-file.json  merge=merge-that-file

For the script at step 1. to work correctly : you need to be able to tell "the latest version" by looking at the files' content, hence my comment about a version number or a date, which you could compare in the script.

Upvotes: 0

Ben W
Ben W

Reputation: 1040

You could use a .gitattributes file to show that it is a binary file. This is documented here

path/to/your/file.json binary

As a note, you can treat the file as text and you will always have the latest version as long as you don't try to change that file in your own branch. Git will merge in all of the text updates for you. If you do make some modifications to the file, then treating it as binary will cause a merge conflict - and you will need to tell git which version of the file to use.

Upvotes: 2

Related Questions