0

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

legoscia
  • 39,593
  • 22
  • 116
  • 167
MomasVII
  • 4,641
  • 5
  • 35
  • 52
  • filter-branch? BFG? – Daniel Mann Apr 29 '19 at 00:16
  • Possible duplicate of [How can I delete a file from git repo?](https://stackoverflow.com/questions/2047465/how-can-i-delete-a-file-from-git-repo) – Daniel Mann Apr 29 '19 at 00:17
  • There is nothing to rm though. The file is already deleted. I'm wondering why it still wants to push it though. – MomasVII Apr 29 '19 at 00:38
  • Because it's in your repo's history, in previous commits. The duplicate link provides methods of removing the file from your commit history (i.e. via `filter-branch`). – Daniel Mann Apr 29 '19 at 01:27
  • 1
    Possible duplicate of [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – phd Apr 29 '19 at 11:51
  • https://stackoverflow.com/search?q=%5Bgit%5D+remove+large+file+history – phd Apr 29 '19 at 11:51

1 Answers1

5

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.

legoscia
  • 39,593
  • 22
  • 116
  • 167