gitbinarybinaryfilesrevision-history

Purposefully disable history for a particular file in Git while keeping most recent version


I am using a proprietary database language for development of my program. The source code is stored in large binaries, and I use a code export utility to save my source code in plain text before committing to my git repository. Since my active source code file is a large binary, I want to update that file in the repository, but I do not care to keep a history for it. The IDE I am using always makes it appear as if the binary has changed, even if I have only made changes to external component files (e.g. xml, manipulated test data, etc...). My question is this:

How can I make git keep only the latest version of this particular binary file, so as to save space in my central repository server? Essentially, I do not want to track history for this particular file, but I still want to keep the most recent copy in my repository.

I searched Google and Stack Exchange for an answer, and I have found similar questions, but no answers for Git.


Solution

  • The source code is stored in large binaries, and I use a code export utility to save my source code in plain text

    How can I make git keep only the latest version of this particular binary file

    To keep only one original-binary version in the repository, not tied to any version of your exported-to-text source, the simplest will be to talk directly to Git's content tracker core for that file:

    git tag latest-binary $(git hash-object -w that.file)
    

    which bypasses almost all of Git and everything else, and makes a reference directly to the bits. You won't be able to check it out normally, instead, use

    git show latest-binary >any.name.you.like