Git wants to push files that don't even exist

Hi peops,

I’m working on a Unity-Project and just created a new branch. But I forgot to exclude the generated lightmaps (huge files). So git says:

<File> exceeds GitHub's file size limit of 100.00 MB

Alright, no problem, I didn’t need them anyway right now, so I deleted the folder and added exclusion to my .gitignore (LightingData.asset)

So lets push again:

remote: error: File Assets/_Scenes/Nobi/T-2/LightingData.asset is 173.19 MB; this exceeds GitHub's file size limit of 100.00 MB

What? The file doesn’t even exist anymore. So I googled, and tried. For hours.

I tried everything the community suggested:

git rm Assets/_Scenes/Nobi/T-2/LightingData.asset

git rm --cached Assets/_Scenes/Nobi/T-2/LightingData.asset

git filter-branch --tree-filter 'rm -rf Assets/_Scenes/Nobi/T-2/LightingData.asset'

git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch Assets/_Scenes/Nobi/T-2/LightingData.asset'

I even did git reset --soft Head~1 and git reset --hard HEAD , readded and comitted and whatnot.

git rm -r --cached .

gave me hopes. I could do the 

git add .

again. So I checked with git status what was about to happen. The Assets/_Scenes/Nobi/T-2/LightingData.asset file was appearing nowhere. So I pushed again, waited about 3 hour for it to do something just to see that it fails again.

What can I do?

I believe the reason for the initial failure was because the file has already been committed, which means it’s in the git history even if you now rm it or exclude it.

I suggest the following, first make a backup of your work, then run

git reset --hard <commit hash>

and use the commit hash before the file was committed. 


git push -f

to make sure the push goes through successfully.

Lastly, add .gitignore and all your project files back, commit and push.

1 Like

Thanks for your reply. I went back quite some commits until the deleted files reappeared in my project. I then removed them via

git rm Assets/_Scenes/Nobi/T-2/LightingData.asset

which now was possible.
Now I could commit again and the console showed me that it will remove the LightingData.asset

Awesome, but as I pushed with

git push --set-upstream origin newBranch

it again took the whole time and told me the same error again.

1 Like

I ended up making a hard copy on my machine and reverted to an old version, deleted my branch and created a new one. Basically what you said, and it was pain.
Thanks :stuck_out_tongue:

Yeah rm does not remove the file from history. Git push will push all files in the git history regardless if its current existence. and Good job!

Mark helpful posts with Accept as Solution to help other users locate important info. Don’t forget to give Kudos for great content!

You can even delete git with rm -rf .git, then git init again if your first commit already includes these large files.

I met the same problem and google for hours as well. Thanks for your post!

For future reference, this issue is not that difficult to understand or solve. It is because when you commit a large file without pushing and then you untrack that large file, commit again and try to push, git still has the old ancestor commit in its history telling it to commit the large file _before you untracked it. _It is doing exactly what you are telling it to do: untracking the file at the point you specified–which unfortunately is after a commit that needs to be pushed. So it wants to push the file, then untrack it.

Sometimes, you may inadvertently commit a large file and then put multiple commits over it without trying to push, which means that you will have multiple commits that need to be re-written before the repo will accept a push.

What you need to do is get rid of any ancestor commits containing the large file. This can be accomplished many ways, such as rebasing and squashing the commits (use 'git rebase -i origin/master [or whatever branch]), doing a tricky and sometimes dangerous ‘git filter-branch’, or my favorite, simply soft resetting the branch you are on to the period before you added the file and recommitting all your changes since then with the problem file now gone. From the sound of it the OP may have tried something like this, but probably didn’t reset far enough back.

What you need to do is remove the file from your working directory (when the problem is solved you can put it in your .gitignore and move it back), then do the following:

Find out how far ahead you are of the remote:

'git status'

It will tell you how many commits you are ahead. If it is 3 commits, do this:

'git reset --soft HEAD~3' (Replace 3 with however many commits you are ahead.)

(Be careful not to mess up this command and do a hard reset, or you will lose your work. It needs to be a soft reset, which resets your git status but leaves your disk untouched…)

Then re-add everything:

git add -A

And recommit:

git commit -m "Squashed commit"


'git push'

It should be as though the file was never committed.


Yup. I love you. thanks for this! Soft reset worked perfectly.

Amazing explanation of the situation and the solution. Thank you so much, greatly appreciated!