Remove git history of big file after file was deleted

80 Views Asked by At

Someone recently created a new branch on my repository, and uploaded a big file (5GB). As a result, no one could pull the repository anymore, since it became to big (pulling works on Mac, but not on Windows, she pushed it on a Mac). When people noticed this issue, she deleted the file from the branch, however, this did not solve the issue, since the file is stuck in Git history (I guess?). How can we make sure we deleted this piece of history? She already tried to remove the file via filter-branch (as described here) but it did not work. Would an option be to delete the branch and then run git garabge collection? The branch was never merged into master and it's okay if the branch would be deleted. She is the only person with a Mac and thus the only person with acomputer that can resolve this issue.

I tried to remove the file from history via filter-branch and git garbage collection, but it didn't work. I also tried to enlarge my postbuffer, but this was without succes.

1

There are 1 best solutions below

1
eftshift0 On

Assuming that the file was added in a recent commit and that no one else has used it (as they can't fetch?), then you could do something like:

git rebase -i X~ # X is the commit where the file was added, make sure to use the 'pig tail' there
# the first line in the list of commits should be the commit where the file was added
# set that first commit to have 'edit' instead of 'pick'
# save and exit
# rebase will stop right after applying that commit and so the file should be right there
git rm --cached the-file # this will remove it from index but the file will still be in the working tree
git commit --amend --no-edit # new commit, the file should be gone from it
git rebase --continur

When the rebase is finished, you now have a branch that does not have that file in history.... now force push it into the remote

git push -f

And now people should be able to fetch from the repo.

Warning: I am oversimplifying by making some assumptions like the branch that you are dealing with is straight.