Sato
Sato

Reputation: 8622

Is it possible to maintain only one revision of certain file in git?

For example, I have a hostname_ip.list.tar.bz2(7MB) file which is a compressed file of hostname_ip.list which is 80MB.

From time to time, I will update hostname_ip.list and compress to hostname_ip.list.tar.bz2 and git commit

So git will keep every revision of hostname_ip.list.tar.bz2, which will cause .git directory very big.

In my case, I don't need old revision of hostname_ip.list.tar.bz2. Is it possible to just keep one version of hostname_ip.list.tar.bz2 ?

Upvotes: 1

Views: 229

Answers (2)

Dan Lowe
Dan Lowe

Reputation: 56697

Whether your strategy makes sense in git depends on the contents of this large file, and how it changes over time.

Note: The rest of my answer depends on assuming that the uncompressed version of the file is text, and line-oriented (i.e. made up of many lines). And that when you change the file, you only change some lines, not all lines.

In that situation, when you change the file, only the changed lines are stored in the commit. In other words, the commits would not be very large (at least, compared to the original file).

In contrast, when you compress the file, you are no longer dealing with line-oriented text-based data. Now, every change, even only 1 byte, causes the entire file to be stored as a new commit. This is one of the main reasons that the prevailing wisdom is to not store binary files in git (at least, not if they ever change).

So it is entirely possible that the simplest option is: don't compress the file at all.

Upvotes: 0

ElpieKay
ElpieKay

Reputation: 30966

Yes, it's possible in Git. But it's not good. git filter-branch and some tools can remove the older versions from all the related commits but doing so always rewrites the history, which means your commit history is unstable. It's okay as long as you don't share your repository with others. If many people co-work on such a project, it's definitely a disaster to maintain the branches.

If you are using Github, you could try its new feature LFS. If you are not, you could use other VCS such as SVN to handle large files. But you need extra work to make a good solution.

Upvotes: 2

Related Questions