1

I've committed and pushed a large folder a long time ago into my repository. As a result, I have a very large pack file (which contains the repository's history).

I'd like to remove that folder from the repository's history as if it were in the .gitignore in the first place. I'd like to do that without having to delete it from my local copy.

I've found similar questions to this one but having tried one of the answers (on a not very important, and small, file) it deletes the file/directory from my local copy, which is not good for my case.

Here are the command I tried:

git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch unwanted_folder' --prune-empty
git gc --aggressive --prune

Thanks in advance.

Eyal
  • 1,649
  • 3
  • 25
  • 49

1 Answers1

1

You will need to rewrite the entire history and push it back up. git-filter-branch (https://git-scm.com/docs/git-filter-branch) does what you want, but I would consider using a tool like BFG: https://rtyley.github.io/bfg-repo-cleaner/.

PressingOnAlways
  • 11,948
  • 6
  • 32
  • 59
  • I used a variation of `git-filter-branch` but it deleted the local copy. I would like a more elaborated answer with some step to get me to the solution. – Eyal Jul 29 '17 at 16:24
  • 1
    @AnDrOiD - think outside the box? Copy your folder to another location on your file system, delete it with git-filter-branch, add it to .gitignore, then copy the folder back? If this is a 1 time operation, doing it manually like that shouldn't be any trouble. – PressingOnAlways Jul 29 '17 at 17:45
  • Tried that already, turns out it didn't remove it from the history. The commands I tried were added to the question. – Eyal Jul 31 '17 at 05:09