I have a knack for accidentally committing large files with git
.
Since git
remotes like github only allow files with size up to 100Mb, pushing this commit will fail.
Therefore, we need to delete the file and roll back the commit.
However, if we tried to delete the file naÏvely ,it will NOT WORK:
# DOES NOT WORK
git rm large_file.csv
git commit -m "undo large file commit"
This is because git
is a version control system, so it need to keep track of history and allow people to checkout old commits -- including the one you had the large file commit.
So this means you'll actually need to change the old commit where you included the large file.
Undoing the file commit, however, is easier than expected. Let's say you committed a large file called "large_file.csv". Then you can undo the commit for this file, and amend the comment:
git rm --cached large_file.csv
git commit --amend -C HEAD
This will fix the git commit and remove the "large_file.csv" from the commit history.