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.

2
  • @phd Nope. Tried that before asking the question. Commented Jul 30, 2017 at 20:53
  • Then its a duplicate of stackoverflow.com/q/24333647/7976758 Commented Jul 30, 2017 at 21:42

1 Answer 1

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/.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@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.
Tried that already, turns out it didn't remove it from the history. The commands I tried were added to the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.