I have a unique situation where I have added 2 >50MB files and Git can't handle them. I have committed them and tried to push but it errors and says it is too large. That's ok for now I can work around but now I have made changes alongside and after adding those files that I would like to keep. So now I have 8 commits ready to push once I can get rid of the large files and have it work again.

I used git rm --cached largefile.whatever and can't see the large files in git diff --stat --cached origin/master but when I push it still pushes for 20 minutes and then says the files are too large.

I also deleted the large files and pushed the delete but still same issue.

I want to keep all my recent work but remove the large files and move on. How can I do this?

Here is my commit process. I wish it was as easy a going back 1 but I dug myself into a hole now. I'm not the best with git so i hope that makes sense.

I can't git rm because the file is already deleted. It's not showing in the directory and says myfile.tif did not match any files

Git Log

1 Answers

legoscia On

You could try doing an "interactive rebase". "Rebase" usually means moving a set of commits onto a different base commit, but in this case we would rebase the commits onto the same place in the tree where they were, only making use of the "interactive" features of the command.

Say that the commit id of the commit that added the large files is abc123. Then you'd run:

git rebase --interactive abc123^

(note the trailing caret: we're rebasing onto the parent of that commit)

This will drop you into a text editor containing something like this:

pick abc123 New garage, touch ups to lava 3
pick def456 ADded garage play, removed giant Tif file
[ ... and so on ... ]

On the first line, change pick to edit, and save and exit. git rebase will now enter a state where that commit has been staged but not yet committed, and you get to modify the commit:

git rm --cached my-large-file.tiff my-other-large-file.tiff

Then type git rebase --continue. It will create a new commit, with the same commit message and the same contents as the old commit except without the large files. Then, it will rebase all the following commits on top of the newly created commit.

Once all that is done, you have a new branch without any trace of the large files, ready to merge into master.