Understanding the Changes in a Git Repository Size After Converting Files to LFS and Deleting Files
Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
Git is a version control system that keeps a record of changes made to files and directories over time. However, when the history of a repository is altered, the size of the repository can change. This can happen due to the conversion of files to LFS or the deletion of files.
Environment
Production
Diagnosis
When a file is converted to LFS in a Git repository, the contents of the file are stored in a separate LFS object instead of in the repository as a regular file. This is done to reduce the size of the repository, as large files can significantly increase the size of a repository.
When a file is deleted using the BFG tool, the entire file and its history are removed from the repository, including any references to the file in the repository's commits. This also reduces the repository size as the file and its history are no longer stored in the repository.
Cause
The reason why the repository size increases after these types of Git history conversions is due to the way Git stores data. In Git, every change to the repository is stored as a separate object in the repository's database. When a file is converted to LFS or deleted, the changes are reflected in the git repository, and the repository's size increases.
For example, when a file is converted to LFS, the file's contents are stored in a separate LFS object, and a reference to the LFS object is stored in the repository. This reference takes up space in the repository, increasing its size. Similarly, when a file is deleted, the reference to the file is removed, but the entire history of the file remains in the repository, causing the repository size to increase.
In conclusion, converting files to LFS or deleting files using the BFG tool changes the size of the git repository, but it reduces the repository size in the long run as large files and their history are no longer stored in the repository. Understanding the changes that occur on the file system level and in the Git repository can help developers make informed decisions about using the BFG tool to optimize the size of their repositories.
Solution
Contact Bitbucket Cloud Support to initiate a garbage collection on the repository.
Was this helpful?