What happens when you accidentally commit a large file in your local repo?

This was the error message I got when I tried to upload my changes to the remote repo. git push origin master.

remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: e397fc16b6c3b712eb7068d69417a5b1
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File final_movie.mov is 317.20 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/trickyj/daboo.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/trickyj/daboo.git'

In order to resolve the above error. I wanted to remove that large size .mov file from my previous commit.

The first thing that came in my mind was to manually delete the final_movie.mov file from my project folder on my laptop. Then commit the changes.

But, this didn’t work. I was still getting the same error. The .mov file was already stored in my .git folder on my local machine project folder.

I searched on git documentation “how to remove the file from the previous commit”
I came across through this document – https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

Removing a File from Every Commit
This occurs fairly commonly. Someone accidentally commits a huge binary file with a thoughtless git add ., and you want to remove it everywhere. Perhaps you accidentally committed a file that contained a password, and you want to make your project open source. filter-branch is the tool you probably want to use to scrub your entire history. To remove a file named passwords.txt from your entire history, you can use the –tree-filter option to filter-branch:

$ git filter-branch –tree-filter ‘rm -f passwords.txt’ HEAD
Rewrite 6b9b3cf04e7c5686a9cb838c3f36a8cb6a0fc2bd (21/21)
Ref ‘refs/heads/master’ was rewritten
The –tree-filter option runs the specified command after each checkout of the project and then recommits the results. In this case, you remove a file called passwords.txt from every snapshot, whether it exists or not. If you want to remove all accidentally committed editor backup files, you can run something like git filter-branch --tree-filter 'rm -f *~' HEAD.

You’ll be able to watch Git rewriting trees and commits and then move the branch pointer at the end. It’s generally a good idea to do this in a testing branch and then hard-reset your master branch after you’ve determined the outcome is what you really want. To run filter-branch on all your branches, you can pass –all to the command.

My issue was resolved.

screenshots for reference

This slideshow requires JavaScript.

 

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s