45

I am getting this error when I try to push to git and I have no idea how to fix it.

Counting objects: 1239, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1062/1062), done.
Writing objects: 100% (1239/1239), 26.49 MiB | 679.00 KiB/s, done.
Total 1239 (delta 128), reused 0 (delta 0)
remote: warning: File log/development.log is 98.59 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: efd2d13efa4a231e3216dad097ec25d6
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File log/development.log is 108.86 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 108.74 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 108.56 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 106.58 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: File log/development.log is 103.70 MB; this exceeds GitHub's file size limit of 100.00 MB
To git@github.com:myUsername/myRepo.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@github.com:myUsername/myRepo.git'

I'm guessing I need to remove the large file from the commit, but how do I do that?

Daniel
  • 1,074
  • 3
  • 10
  • 17

10 Answers10

37

To remove large files, GitHub suggests:

$ git rm --cached giant_file
# Stage our giant file for removal, but leave it on disk

git commit --amend -CHEAD
# Amend the previous commit with your change
# Simply making a new commit won't work, as you need
# to remove the file from the unpushed history as well

git push
# Push our rewritten, smaller commit

Or if you want more general information on how to work with large files on GitHub.

And next time add /log in your .gitignore

Daniel Andrei Mincă
  • 3,696
  • 2
  • 17
  • 30
19

I faced the same issue recently, you can actually just filter the branch for specific file and remove it -

git filter-branch --tree-filter 'rm -rf path/to/your/file' HEAD
Ritesh Chandnani
  • 365
  • 3
  • 13
  • 1
    You need to run this command from the toplevel of the working tree. –  Jan 02 '20 at 01:59
18

To improve upon one of the reply above, you need

git filter-branch -f --tree-filter 'rm -f /path/to/file' HEAD --all

in order to remove your file even from the history. You need -f to force rewriting any backup and --all to remove file from all branches. More information here: Git docs

Your large file error won't go away by removing it from the git cache because it is still lurking in the commit history.

user30850
  • 181
  • 1
  • 3
5

git reset --soft HEAD~1

then exclude the file from the commit.

Note: Use HEAD~N to go back to N number of previous commits.

use this , go back a commit ,remove the large file from the commit if you can see it , then re commit and push.

this should solve the problem

5

I had already deleted the file thinking that would help. Running this command on the the branch worked for me.

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path/to/file'
CZTopp
  • 51
  • 1
  • 2
3

Adding to the previous answers:

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_to_the_file/your_big_file'

Additionally, when I tried to pull I got "Refusing to merge unrelated histories".

Solution was to use:

git pull origin branch_name --allow-unrelated-histories

Then solve your possible conflicts, and push this time without the big_file.

Kim
  • 3,463
  • 2
  • 26
  • 48
Timbus Calin
  • 11,679
  • 3
  • 35
  • 51
3

Adding to the previous answers:

We are going to remove the large file from the commit as you said

  1. Do the push from the terminal just to get the large file path git push --set-upstream origin Remote_branch_name, locate the large file path in the errors, something like RepositoryName/folders.../bigFileName.

  2. Remove the file from all the branches, git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch path_and_big_file' past the path that we found in section one instead of path_and_big_file.

  3. Execute git pull origin branch_name --allow-unrelated-histories to not get unrelated histories error

  4. Now try to push to git, it should work

Guy Luz
  • 2,714
  • 14
  • 35
0

You can revert git add before commit.

Check this question: How to undo 'git add' before commit? It should work. And don't send big files to git, it's not worthy ;)

Also, exclude your logs, by adding git ignore on your logs path.

Community
  • 1
  • 1
m.aibin
  • 3,368
  • 4
  • 28
  • 45
0

@Daniel

You can ignore that log(s) file from git repo using .gitignore file. for that you have to add below line to your .gitignore file

/log

and try to commit again.
Hope this details help you to fix your issue.

hgsongra
  • 1,456
  • 15
  • 23
0

This command worked for me

git filter-branch -f --index-filter 'file path'