3

I'm having trouble with a git repository (that is, a GitHub repo to which I push via git command-line tool).

It is a Rails app. One of the functionalities it implements is the download of .zip files... Which, by design, are created and temporarily stored on the server (localhost). Problem is the auto-delete hasn't been implemented yet. So, with .zip files around 120MB in size on the "server", I decided to git add -A, git commit -m "blabla" and git push. Pushing took forever, ending up in an error message along the lines of "the file is too big, push aborted".

I gave up on pushing that day and deleted the problematic file instead. I kept on working the next days, opened a new branch, checked back out to branch master, tried to add -> commit -> push but... The error message about the size-exceeding .zip file was still there!

What's going on?!

Please help me out!

kisa_svnt
  • 33
  • 3
  • do you push per http or ssh/git ? – Rufinus Sep 06 '14 at 14:33
  • I think it's via https... I use the git command line utility. How would this affect my problem? – kisa_svnt Sep 06 '14 at 15:04
  • depending on the remote repository, there can be a limit of post (push) size. with SSH/GIT there isnt a limit. it does not matter if you use cli or gui, it all depends on the remote orgin url. see http://git-scm.com/book/en/Git-on-the-Server-The-Protocols for more info – Rufinus Sep 06 '14 at 23:30

1 Answers1

4

When you ran git add; git commit then git added the zip file to your local repository. Even though you deleted the local file, git still has it in the repo since it keeps a copy of every file ever committed.

Since you've already committed the file to your local git repo, you'll need to remove it from the history before you can push. In order to do that, follow this answer: https://stackoverflow.com/a/2158271/1695439

The answer boils down to running git filter-branch and then deleting your original branch. Remember to replace giantfile.zip with the filename of your giant zip file.

$ git filter-branch --index-filter 'git rm --cached -r --ignore-unmatch giantfile.zip' --prune-empty --tag-name-filter cat -- --all
$ git update-ref -d refs/original/refs/heads/master
$ git reflog expire --expire=now --all
$ git gc --prune=now
Community
  • 1
  • 1
magikid
  • 308
  • 2
  • 11
  • Hey magikid, under each answer is a share link. You can use that to get a link to an answer that most applies to this situation. Additionally, it's not a bad idea to quote some of that answer here and then tweak it if you can make it more applicable to this specific situation. – jamesmortensen Sep 06 '14 at 19:48
  • Do you think it's best to create a new branch before attempting this, just in case something goes wrong? Does this affect the entire repository or just a single branch? – jamesmortensen Sep 06 '14 at 20:03
  • The `git filter-branch` I've given above will remove the file from all branches (and commits) in the repo. As for in case something goes wrong, the docs for [git-filter-branch](http://git-scm.com/docs/git-filter-branch) suggest either making a backup of the repot before running the `git update-ref` part or using `git clone file:///path/to/repo` as that will clone the repo without the removed files but your original will still be intact in ref/original/. – magikid Sep 06 '14 at 20:32