0

Environment :

Windows 10

I wanted to push some files on my remote master github repository. There was an issue with a file which is too large.

So I removed it with the command:

git rm modules/db.db

I made a commit and when I tried to push again my local branch to the master, I get again the same error message:

C:\Users\gauth\Documents\github\abc>git push origin master
Enumerating objects: 263, done.
Counting objects: 100% (263/263), done.
Delta compression using up to 6 threads
Compressing objects: 100% (262/262), done.
Writing objects: 100% (263/263), 49.93 MiB | 6.17 MiB/s, done.
Total 263 (delta 75), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (75/75), done.
remote: error: Trace: 68110557c386982431ba3a2ec8e09d4c9ee8400e835d0490d29c096b851007e1
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File modules/db.db is 144.78 MB; this exceeds GitHub's file size limit of 100.00 MB
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/abc/abc.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/abc/abc.git'

I don't understand why git doesn't take this removal! Why does it still want to upload a removed file? Can anyone help me, please?

Gauthier Buttez
  • 1,005
  • 1
  • 16
  • 40
  • The trouble is that you are pushing multiple commits and they have the problem file still. One possibility: Try `git reset --soft origin/master`. Now commit and push. That way you are pushing just _one_ commit and it lacks the problem file. Of course you have also squashed your history so don't do it if that's not acceptable. – matt Aug 16 '21 at 12:18
  • By the way, the very error message you quoted contains a link (http://git.io/iEPt8g) that tells you what to do. – torek Aug 16 '21 at 12:28

1 Answers1

1

Files don't precisely exist in branches. They exist inside commits—which are then contained within branches, so you can get from point Z back to point A, but you have to go through all the intermediate points first.

This is precisely your problem: the large file modules/db.db exists in a whole bunch of commits (or maybe in just one commit). When you run git rm and then git commit, you make a new commit. The new commit omits the file, but all the existing commits still exist, and still contain the file.

You must find all the existing commits that contain the large file, and fix them—which itself is impossible: no existing commit can be changed, ever: not by you, and not by Git itself. So, that means you must find all the existing commits that contain the large file, and throw them out entirely.

If they have valuable data in them, you'll want to copy the valuable data out of those commits, into new-and-improved commits that are just like the originals, except that they omit this large file. You'll then want to rearrange your existing branch names so that instead of finding the old commits—which are no good because they contain the large file—they find, instead, the new and improved commits.

If the old commits have no valuable data in them at all, you can just toss all of them out, and make a new final commit that stores the right files, and omits the large file.

See How to remove/delete a large file from commit history in Git repository?

torek
  • 448,244
  • 59
  • 642
  • 775
  • Buried deep in that linked question is an [answer](https://stackoverflow.com/a/61602985/184546) mentioning `git-filter-repo`, which maybe is the way to go nowadays. – TTT Aug 16 '21 at 16:47