0

I am trying to remove some large files from my git repository.

After a fair amount of browsing I have come across the following solution,

git_delete_file() {
    git filter-branch -f --index-filter "git rm -r --cached --ignore-unmatch $1" --prune-empty
    git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
    git reflog expire --expire=now --all
    git gc --aggressive --prune=now
}

git_file_space() {
    git rev-list --all --objects | 
        git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' | 
        grep blob |
        sort -k3nr |
        head -n 20
}

However, when I run git_delete_file large/file/path and then git_file_space the files are persisting. I have not tried to download git-filter-repo but I am considering it a last resort.

Regards Jordan

  • 1
    `git-filter-repo` is more conventional for this anyway; no reason to avoid it... – Makoto Jan 10 '23 at 23:50
  • Does this answer your question? [How to remove/delete a large file from commit history in the Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-the-git-repository) – Inigo Jan 11 '23 at 08:17
  • Not exactly, my question was why `git filter-branch` was not actually removing the file, not how to remove the file. Thanks anyway. – Jordan Dennis Jan 11 '23 at 22:59

1 Answers1

0

I have not tried to download git-filter-repo but I am considering it a last resort.

It is true you need to install it (after installing Python), but after that, removing a file is simply, using path-based filtering:

git filter-repo --invert-paths --path 'path/to/large/file' 

That seems easier than the all filter-branch + update-ref + reflog + gc workflow.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250