-2

I have a git repo with a large file in it. When I try to push the latest commit, I get

git push

Uploading LFS objects: 100% (3/3), 14 MB | 0 B/s, done.
Enumerating objects: 72, done.
Counting objects: 100% (72/72), done.
Delta compression using up to 8 threads
Compressing objects: 100% (46/46), done.
Writing objects: 100% (48/48), 119.54 MiB | 1.20 MiB/s, done.
Total 48 (delta 18), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (18/18), completed with 13 local objects.
remote: error: Trace: 2d9cbf92a61dcf330db8f0eb15fe40fd5c4278a487ab3faa3c9f8feaf93d9675
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File template.pptx is 119.59 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.

I added the problem file "template.pptx" to .gitignore which now has:

*.mp4
~$*.pptx
template.pptx

I also added it as a filter to go to git LFS in gitattributes:

# Auto detect text files and perform LF normalization
* text=auto
# LFS support for .trec files
*.trec filter=lfs diff=lfs merge=lfs -text
template.pptx filter=lfs diff=lfs merge=lfs -text

And I removed it from the directory and from the cache:

>ls template.pptx
ls : Cannot find path 'template.pptx' because it does not exist.
>git ls-files -- "template.pptx"
>

How can I stop git from trying to push this committed file to the remote repo? Also, why is it not included with the other LFS files?

user1443098
  • 6,487
  • 5
  • 38
  • 67
  • 1
    Gitignore doesn't effect already commited files – mousetail Oct 14 '22 at 14:42
  • 1
    Either reset to the previous commit and re-commit without that file, or rebase interactively and do the same. Have you tried searching? This has been asked hundreds of times. – CodeCaster Oct 14 '22 at 14:52
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+file+history – phd Oct 14 '22 at 15:10

1 Answers1

1

You cannot remove a file if it's already commited.
You will need to update the existing commit containing the addition of this file (technically do another commit).
Let's say it was added in the last commit. What you can do is :

  • git reset HEAD~ to go back 1 commit before but still keep the changes in your working directory
  • mv template.pptx to remove the file from here if you need
  • git add ... to add all the files you want (and update you .gitignore file if needed)
  • git commit commit again but this time without the file
  • git push if you push now, the commit without the file will be pushed and not the other one (which still exists but not referenced anymore, so it will be deleted eventually by git's garbage collector)
Matt
  • 3,422
  • 1
  • 23
  • 28