4

I accidentaly committed some very large PDF files that were well over GitHub's size limit, so when I later pushed, I got an error, and wasn't able to push. Now, I want to remove those files from the commit, without losing them locally, so that I can later add .pdf in .gitignore and commit and push my other changes. Does anyone know how I can do this?

I do not want to undo any changes, or risk to do that.

bjornasm
  • 2,211
  • 7
  • 37
  • 62

2 Answers2

9

Backup these files first

Open terminal, cd to your git directory and

git log

You will see something like this:

enter image description here

Then copy the commit hash before the addition of these large pdf files and run this command

git reset --soft <good commit hash>

now you can push your local changes

Community
  • 1
  • 1
Jossef Harush Kadouri
  • 32,361
  • 10
  • 130
  • 129
  • But the (unreachable)blobs would still be there, right? Should OP run "git gc --aggressive" too or is this something that is taken care of when git push is done? – Aravind Aug 01 '15 at 10:51
9

You can try this:

git rm *.pdf
git commit --amend

I think this should fix your commit locally and then you can push it.

EDIT

Copy your PDFs to another location as the rm command will delete them from the git directory.

nalyd88
  • 4,940
  • 8
  • 35
  • 51
  • git rm *.pdf zsh: no matches found: *.pdf Any idea why I get this? – bjornasm Aug 02 '15 at 12:34
  • Are the PDFs still in the git directory? – nalyd88 Aug 05 '15 at 02:22
  • I'm not sure why it isn't working. If they are currently in the latest git version and branch `git rm *.pdf` should work (verified on my system even with the PDFs removed from the directory). Have you perhaps already removed them/reset the commit? – nalyd88 Aug 05 '15 at 02:29