I have a .NET C# repository. Included is a binary executable which builds a database based on a number of regularly updated SQL scripts also in the same repository. Naturally, the bin
folder is ignored using .gitignore
.
However, I have some non-developer users who need to get regular updates to this file. Ideally what I'd like to do is put a simple batch script on their machine that does a git pull
and receives the new binary. However, I really don't want to track history to this file and clog my repository with unnecessary data.
Is it possible to commit a file without retaining history of that file? So every time I commit the file, it just replaces the object stored in the repository, instead of creating a new version of that object.
If not, do any of you have any very simple solutions for this. The file is just an internal utility used by 5 or 6 staff members, so any kind of hack solution will do.
You should use Git LFS if you have large files or binary files to store in Git repositories. That's because Git is decentralized. So, every developer has the full change history on their computer.
It's important to never commit binary files because once you've commit them they are in the repository history and are very annoying to remove. You can delete the files from the current version of the project - but they'll remain in the repository history, meaning that the overall repository size will still be large.
It can, literally, compress (or "deltify") any binary data against any other binary data—but the results will be poor unless the inputs are well-chosen. It's the input choices that are the real key here. Git also has a technical documentation file describing how objects are chosen for deltification.
Git stores the complete history of your files for a project in a special directory (a.k.a. a folder) called a repository, or repo.
You can create a blob for the binary file and tag the blob, when you replace the binary file, you actually create a new blob, prune
the old one, delete the tag, create a new tag pointing the new blob.
Follow the following steps to create a blob and tag the blob:
cat my_binary_file | git hash-object --stdin -w | xargs git tag -a tag_my_binary_file -m 'this is the message describing the binary file'
git push --tags
Now you have created a blob for my_binary_file
and created the annotated tag tag_my_binary_file
pointing to the blob, and pushed the tag and blob to upstream. You can checkout the binary file from another client with the following steps:
git fetch --tags
git cat-file -p tag_my_binary_file | head -1 | cut -d" " -f2 | xargs git show > my_binary_file
Now you will find your binary file named my_binary_file
in the current directory.
For replacing the file, follow the following steps:
git tag -d tag_my_binary_file
git gc
; git prune
You can maintain that file on a separate orphan branch (git checkout --orphan NEWBRANCH
), and commit your file there.
When you need to replace the file, commit it with --amend and then force-push that branch.
This will overwrite previous commit, so you will only ever have single revision of the file at any given time. On the client side you can get content of the file either by checking out the branch with the file or by using git show branch:file > file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With