0

I have a simple project on Git, but I unfortunately committed a 200mb file about 4 commits ago. This means I cannot push it to origin since it exceeds the 100mb file size limit of Github. I've since removed that file in subsequent commits but it stays in commit history, preventing me from pushing to origin. How do I remove that one old commit while keeping my most recent ones intact?

IronWaffleMan
  • 2,513
  • 5
  • 30
  • 59
  • This question has been asked dozens of times on [so]. Search for it and you'll find the answer (it uses [`git filter-branch`](https://git-scm.com/docs/git-filter-branch) or a tool called [BFG Repo-Cleaner](https://rtyley.github.io/bfg-repo-cleaner/). – axiac Apr 14 '18 at 20:17
  • 3
    Possible duplicate of [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – axiac Apr 14 '18 at 20:18

1 Answers1

0

This is easiest to do using rebase. I recommend the interactive rebase method, described in this answer.

But there is a more direct way. First, find which commit exactly is problematic. Let's say it's commit 1234abc. You can remove that commit from your history using git rebase --onto 1234abc^ 1234abc.

You will have to fix up some commits as the rebase runs. If you panic, you can get back to before you started the rebase with git rebase --abort. The rebase will probably ask you to resolve some conflicts, such as in the commit where you removed the (now non-existent) file. There is nothing to remove there; probably git rebase --continue will make the rebase proceed.

After the rebase, the original file contents will still be present in your .git folder, but you should still be able to push to GitHub. If you also want to shrink your .git folder, then run git prune.

Bram Geron
  • 273
  • 1
  • 12