koyamashinji
koyamashinji

Reputation: 645

Push error from large files even after adding it to gitignore and unstaging

The following error is thrown when trying to push commits to my private repo (my own project no one else has access to) on Github:

remote: Resolving deltas: 100% (16/16), completed with 10 local objects.
remote: error: Trace: XXXX
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File file1 is 103.40 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 XXX.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'XXX.git'

I know this is caused by the large file file1 I have in my local repo.
This is the exact flow of what I typed prior to the push:

1

git add -A

2

I realised I forgot to gitignore the large file so I added it to .gitignore.

3

git rm -r --cached .  # reset all the staged changes 

4

git status

Here I knew the large file was unstaged by seeing deleted: file1.

5

git commit -m "20211120backup"

Here I was able to double-check that the large file is removed by seeing the delete mode 100644 file1. (Below is a console output).

Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
Enumerating objects: 91, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), done.
Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
warning: There are too many unreachable loose objects; run 'git prune' to remove them.
[main 6a86997] backup20211120
 4 files changed, 3 insertions(+), 8 deletions(-)
 delete mode 100644 file1

6

Finally, below to lead to the said error.

git push

Why does git still trying to add the large file to the repo, even after adding them to .gitignore and resetting all the staged commits?
How to fix this?

Thanks for your help.

Upvotes: 1

Views: 1531

Answers (1)

koyamashinji
koyamashinji

Reputation: 645

I solved this by the following.

Check your log of commits.

git log

It shows the console output like this:

commit AAAA (HEAD -> main)
Author: koyamashinji 
Date:   Sat Nov 20 16:49:08 2021 +0900

    backup20211120

commit BBBB
Author: koyamashinji 
Date:   Sat Nov 20 15:32:23 2021 +0900

    backup20211120

commit CCCC
Author: koyamashinji 
Date:   Sat Nov 20 15:24:47 2021 +0900

    backup20211120

commit DDDD (origin/main, master)
Author: koyamashinji 
Date:   Sun Nov 14 18:15:27 2021 +0900

    initial backup

Go back to the commit BEFORE adding the large file. (which in this case was commit DDDD.

git reset --soft DDDD

After that, just push normally like below.

git add -A
git commit -m "my_commit"
git push

Upvotes: 2

Related Questions