I have to remove a number of files from a git repo on gitlab.com that are tracked with Git LFS. They were automatically updated in a nightly CI build over a number of weeks and I quickly ran out of storage space.
I have followed the original documentation on cleaning up a gitlab repo, but found it to not lower the used storage space. I probably did something wrong in my attempt to not delete this file across the entire history, but just within a certain date range.
The following steps using the bfg repo cleaner instead of git-filter-repo ended up working:
(Note: git rev-list
is your friend! This was the main thing that helped me filter out exactly which objects to delete from history. It's worth looking at its options!)
6.
tar xzf project-backup.tar.gz
git clone --bare --mirror /path/to/project.bundle
project.git
directorygit remote set-url origin https://gitlab.example.com/<namespace>/<project_name>.git
.jar
file from here<YYYY-MM-DD>
with the start/end dates between which to scan the git repository for the file marked as <file path in repo>
):
git rev-list --all --objects --since <YYYY-MM-DD> --before <YYYY-MM-DD> | grep <file path in repo> > object_ids_to_delete.txt
<Object ID> <file path>
, so just remove all instances of <file path>
bfg
on the repo with the given set of object IDs: java -jar bfg.jar -bi ./object_ids_to_delete.txt ./project.git
cd ./project.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
(see bfg docs)git config --unset remote.origin.mirror
git push origin --force 'refs/heads/*'
push
-steps weren't necessary for me...)bfg
generates: it should be in ./project.git.bfg-report/<date>/<timestamp>/object-id-map.old-new.txt