1

I accidentally added and committed a folder with some large binary files in my git repo. When I went to push it to remote git complained so I made a commit that deleted the folder and git was happy again. Fast forward a few weeks and that commit now lives on a branch that has multiple commits and merges on top of it and I'm now finding out that some of our other development tools such as code review don't want a file that large in the history at all and I have no idea how to remove it. I can't just delete the commit because it contains other important files that are needed in subsequent commits/merges on that branch. Is there any way to surgically remove a single file/folder form a very specific historic commit?

John Devitt
  • 690
  • 2
  • 8
  • 22
  • are you allowed to change the whole history? – OznOg Nov 02 '17 at 16:16
  • 2
    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) – phd Nov 02 '17 at 16:30
  • Can you just squash the commit history on the affected branch using `git rebase -i`? That would allow the code review to move forward. – JDB Nov 02 '17 at 17:54

1 Answers1

1

You can use git filter-branch pretty easily for that. The help page contains examples exactly for your case.

It does of course rewrite history with all applying caveats, but there is no way around that fact if you truly want to get rid of that large file.

AnoE
  • 8,048
  • 1
  • 21
  • 36