How to remove a "too large" file from git history?

I added a 212MB file to my folder and committed it and tried to push. Git told me the file size is too big so I can't push it. I deleted the file, but it still shows up when I try to push my code.

My valid steps:

  • I did git add .

  • Then git commit -m "New css"

  • Then git push origin development

  • Then it took a long time to execute the above command. It ended up with "path / to / file / file.mp4 is too large at 212MB. Failed to push."

  • Then I manually deleted this file.

  • I tried to repeat the same thing.

I've been told by other stackoverflow answers to use git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD

I'm just trying to figure out what this means. Will this affect my entire repo or just the above file? What happens if I manually delete the file already? So the file path does not exist.

For example, since I tried to push to the development branch, I did git push origin development

. It failed, so assuming the file I'm trying to delete is called Testing.mp4, if this is the code:

git filter-branch --tree-filter 'rm -rf public/uploads/videos/testing.mp4' HEAD

I'm right? Again, will this ONLY delete the video and nothing else?

Many thanks for the help

+3


source to share


2 answers


removing a file from the filesystem does not necessarily mean removing it from git if it was previously added to the index (git add path / to / file), but just record the delete operation.

Depending on what you did earlier, git might try to nudge your various actions into order: first add the file (which fails because of the file size), then delete it.

To stop tracking this file, you can try to remove it from the index: git rm --cached path / to / file



Remember later to always "git rm" the problematic file, not just delete it, git rm will delete the file and remove it from the index at the same time.

Here's a nice extension from manojlds: "git rm --cached x" vs "git reset head-x"?

Hello

0


source


your project contains files over 100MB in size, you can remove these large files with BFG Repo-Cleaner before returning to github. There is a guide on how to troubleshoot the Github import error: "We encountered an error while importing . " Don't forget to back up your project source and git database



0


source







All Articles