5

When I do the following:

git add *
git commit -m "msg"
git push origin develop

I get the following errors:

Counting objects: 25, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (25/25), 46.43 MiB | 2.49 MiB/s, done.
Total 25 (delta 13), reused 0 (delta 0)
remote: Resolving deltas: 100% (13/13), completed with 11 local objects.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: ffe0c9f32d9cde4cedfc1f4713eb82b9
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File tags is 282.99 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://mygithubrepo
 ! [remote rejected] develop -> develop (pre-receive hook declined)
error: failed to push some refs to 'https://mygithubrepo'

I have then deleted the file 'tags' from my hard disk but every time I try to push, I get the same error. The file has never been pushed to my repository, so I just need to remove it from this current commit. I have tried numerous things, but I end up with this same error every time. Any help?

When I do

git ls-files

The file 'tags' does not even show in the list. But still it is trying to push it?

2 Answers2

10

This should work:

git rm --cached <big_file>
git commit --amend .

This deletes the file from tracking, and then modifies the previous commit to also not include this file.

Derek Brown
  • 4,232
  • 4
  • 27
  • 44
  • 2
    I think it's important to point out that you do need to amend (as indicated in this answer), not create a new commit. Without amending, the large file still exists in history, and the push will be rejected. – jhpratt Mar 02 '18 at 20:35
  • So this will mark the file as untracked? – cst1992 Mar 02 '18 at 20:35
  • Yes, assuming the file is included only in your most recent commit. – Derek Brown Mar 02 '18 at 20:35
  • I can not do the git rm --cached tags.txt because I think I have already done it earlier. And also the file doesn't exist on disk anymore. When I do git commit --amend I get the following: -------------------- commit-msg.. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Fri Mar 2 19:53:41 2018 +0100 # # On branch develop # Changes to be committed: # deleted: tags # -------------------------- I then exit and try to push, but the same errors shows up again – – Simon Sondrup Kristensen Mar 02 '18 at 21:32
  • @SimonSondrupKristensen try `git reset --hard HEAD && git rm --cached && git comit --amend -m "removed big file" .` – Derek Brown Mar 02 '18 at 23:22
5

Derek's answer is right if you added the big file in your last commit. Also if you want to avoid to add it again, then add it to your .gitignore file.

So, first:

git rm --cached <big_file>

Then edit your .gitignore file adding the big file name.

Finally add these changes to the stage

git add .

At this point if you create a new commit, you won't be able to push, because the file will be in your git folder anyway, so you need to create a fixup commit in order to amend the commit where you added the big file with:

git commit --fixup <old-commit-hash>

Once you're ready with that, you'll need to rebase, and there are 3 cases:

1 - You're committing everything on master:

git rebase <old-commit-hash>^ -i --autosquash

2 - You are in a branch and your big file commit is in the same branch:

git rebase master -i --autosquash

3 - You are in a branch and your big file commit is in an already merged branch:

git rebase <old-commit-hash>^ -i --autosquash --preserve-merges
xyzale
  • 745
  • 8
  • 14