9

I made a "little" mistake and added a "little" (>100MB) file to my local repo.

Two commits later I'm trying to push to remote repo in github that have a limit of 100MB.

I can remove the file from my current commit with git rm --cached, but it still in previous commits.

How can I remove the file from all commits? I've tried this answer about git filter-branch but don't work for my.

3
  • 1
    Filter branch is the way to go AFAIK. You could also do an interactive rebase in which you remove that large file from the initial and all subsequent commits. Jun 24, 2017 at 9:56
  • Thanks @TimBiegeleisen I don't know why but it does not work for my, any way I've found stackoverflow.com/questions/307828/… with a marvelous answer.
    – Mquinteiro
    Jun 24, 2017 at 10:05
  • This answer will help you . stackoverflow.com/a/28173964/94311 . Basically you check out the wrong commit,remove the unwanted file,rebase all the other commits
    – Rohith
    Jun 24, 2017 at 10:36

3 Answers 3

5

You could change the last 3 commits by interactive rebase.

git rebase -i HEAD~3

And change the commit to "edit".

See https://help.github.com/articles/about-git-rebase/

2

I would soft reset the 3 latest commits. Then remove the "little" file. Then make all the changes into 1 new commit.

It's not really ideal I think but solves the problem cause you haven't made too many additional commits yet.

1
  • Couldn't agree more... Sometimes the systematic solutions in GIT are too convoluted. Jun 24, 2017 at 12:57
2

Concerning the observation:

I've tried this answer about git filter-branch but don't work for my.

Further details on why the linked answer doesn't work would be useful. Leaving that aside, I've successful used the code below on multiple occasions to achieve the same objective:

git filter-branch --force --index-filter \
    "git rm --cached --ignore-unmatch <your-file>" \
    --prune-empty --tag-name-filter cat -- --all

This command is broadly similar to what is being discussed in the answer that OP linked. For clarity, it is worth adding that this command was discussed in the Removing sensitive data from repository GitHub help article1.


1 It appears that article have moved so I've linked the archive.is page.

1
  • This definitely solved my problem thank you! I like this approach as well as I was able to target the file as intended. Now I can push remotely since the file was actually removed.
    – JahkR Code
    Feb 13, 2023 at 6:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.