Git Large File Storage (LFS) is used to manage large files in a git repository. If you want to remove a file from Git LFS, you'll need to follow a few steps. Below are the typical steps to achieve this:
1. Confirm the File is Tracked by Git LFS
First, confirm that the file you want to remove is tracked by Git LFS.
git lfs ls-files
2. Untrack the File
To untrack a file in Git LFS, use:
git lfs untrack <path-to-file>
This command will remove the entry from the .gitattributes file.
3. Remove the File
Remove the file from your working directory and commit the changes:
4. (Optional) Modify History to Remove the File from LFS
If the file had already been committed and you need to completely remove it from the history, you will need to rewrite your git history. This is an advanced step that can impact collaborators, so use with caution.
First, install the bfg tool if it's not already installed:
brew install bfg
# or for other platforms
# Download from: https://repo1.maven.org/maven2/com/madgag/bfg/1.13.0/bfg-1.13.0.jar
Run bfg to remove the file from history:
bfg --delete-files '<file-name>' <path-to-repo>
After using bfg, you need to perform a garbage collection:
Backup: Always backup your repository before performing history-rewriting operations.
Communication: Inform your team and collaborators before rewriting history as it changes commit hashes and can lead to conflicts.
Git LFS Storage: Be aware that removing a file from your repository doesn't necessarily remove it from Git LFS storage. You might need additional steps to reclaim storage space.
After these steps, the file should be untracked and removed from Git LFS in your Git repository.