9

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

My actual steps were:

  1. I did git add .

  2. Then git commit -m "New css"

  3. Then git push origin development

  4. Then it took a long time to run the above command. It ended with saying "path/to/file/file.mp4 is 212MB which is too big. Failed to push".

  5. Then I deleted that file manually.

  6. Tried pushing again, same problem.

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

I'm just trying to understand what this means. Will this affect my whole repo or just the above mentioned file? What happens if I manually deleted the file already? So the file path doesn't exist.

For example, since I tried pushing to the development branch, I did git push origin development. This failed, so assuming the file I'm trying to delete is named Testing.mp4, should this be the code:

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

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

SilentCloud
  • 1,677
  • 3
  • 9
  • 28
LizzyTheLearner
  • 241
  • 1
  • 3
  • 10

2 Answers2

3

Deleting the file from filesystem won't necessary mean removing it from git if it was previously added to the index (git add path/to/file), but just record a delete operation.

Depending on what you did previously, git may be trying to push your various actions in order: add the file first (which fail due to file size) then delete it.

To actually stop tracking this file you could try to remove it from index: git rm --cached path/to/file

Remember later to always git rm a problematic file rather than simply deleting it, git rm will delete the file AND remove it from index at the same time.

A good expanation from manojlds lies here

SilentCloud
  • 1,677
  • 3
  • 9
  • 28
  • Hey, thank you for the answer. I updated my question. Should I still do "git rm --public/uploads/videos/testing.mp4"? – LizzyTheLearner Jul 17 '17 at 02:52
  • @LizzyTheLearner probably should still do `git rm --cached /path/to/file` – Eddie Jul 17 '17 at 03:01
  • According to your actions, "git rm" and "git rm --cached" should have the same effect, git rm won't complain if the file is not found. But since you committed the whole thing, the delete operation will still occur ... – Antoine Prevot Jul 17 '17 at 03:04
  • @Eddie It gives me the following error "fatal: pathspec path/to/file did not match any files". I tried both git rm and git rm --cached :( – LizzyTheLearner Jul 17 '17 at 03:07
  • What is the output of "git ls-files", do you still see your file appearing ? – Antoine Prevot Jul 17 '17 at 03:15
  • By the way, another way to "come back" would be to reset your repository to a working commit since the push failed, ie for the previous commit : git reset --hard head~1 (make a copy of your files first just in case ;)) – Antoine Prevot Jul 17 '17 at 03:23
  • @LizzyTheLearner why not check `git status` and see where your deleted file go? if it's in the removed section, then you might want do another `git add .` `git commit -am "delete large file"` – Eddie Jul 17 '17 at 03:38
  • @Eddie and Antoine, thanks guys. I did git filter branch and it worked – LizzyTheLearner Jul 17 '17 at 03:40
  • Glad you could save your repository ! You should maybe edit your question to include the working solution since my answer was not relevant in your situation :/ – Antoine Prevot Jul 17 '17 at 03:44
0

your project contain files with size larger than 100MB, you can remove these large files using BFG Repo-Cleaner before putting to github.

There is a tutorial about How to solve Github import error: "We found an error during import". Remember to backup your project source code and git database.

Dowload BFG, clone your repository with --mirror flag and just run:

java -jar bfg-1.13.0.jar --no-blob-protection --strip-blobs-bigger-than 100M your-repo.git

cd your-repo.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push