10

I had some large files in my github repository which I tried to add/commit/push but the push command gave the following error

remote: error: File app_dump.sql is 106.67 MB; this exceeds GitHub's file size limit of 100.00 MB

So I deleted the large file (app_dump.sql) from my repository and did again add/commit/push. But I think this was not the right thing to do, because whenever I push it will still try to push the large file?

$ git status
On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean

so now I get the same filesize error every time I push. How can I remove the file from git? I tried

$ git rm app_dump.sql
fatal: pathspec 'app_dump.sql' did not match any files

but this did not find any file, because I deleted it... thanks carl

carl
  • 4,216
  • 9
  • 55
  • 103
  • You need to checkout a branch at the revision before you added the big file. Rebase everything except adding the big file on top of that. That becomes your new "master". – Thilo Feb 06 '16 at 12:25

3 Answers3

14

Try reverting the commits you made:

git reset HEAD~1

This should undo 1 local commit. Undo your local commits until before the large file was included. Delete the large file. Commit your changes then push.

4

See this article: https://help.github.com/articles/remove-sensitive-data/ . Basically you want to rewrite you repository history. But always careful with the git filter-branch command!

git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch app_dump.sql' \
--prune-empty --tag-name-filter cat -- --all

If I were you I'd make a local backup of the repository first. Simply copy the whole folder to some other location so that you can experiment on your repo in piece.

When you are happy with the results commit them to Github, and remember that this rewrites history so any file deleted here will disappear from Github's history too.

Harald Nordgren
  • 11,693
  • 6
  • 41
  • 65
  • On Windows you need to use double quotes instead of single quotes. Also, note that you can use wildcard in file specs. The path mus have "/" as seperator on both Windows and Linux. – Shital Shah Jan 05 '19 at 00:25
4

After deleting the file still stays in git commits, so you'll have to edit git history to remove the file from the commit where you have added it first.

Do an interactive rebase on the commit before it:

  • git rebase -i ThatCommitSha~1 and put edit on the line with that commit (change "pick" to "edit" in the editor on the line with ThatCommitSha, then save the file – See Docs.)
  • rebase will stop at that commit, git rm the file and commit --amend
  • git rebase --continue to link all next commits (they will be changed too, because the commit-with-file sha will change)
MikeiLL
  • 6,282
  • 5
  • 37
  • 68
Vasfed
  • 18,013
  • 10
  • 47
  • 53