问题
I erroneously committed a big file (>100Mb) that I really didn't have to include in my git history.
I removed the file, also, I removed it from git cache, then I committed again.
Despite this, when I try to push to my remote branch, git gives me a size error.
I also tried a git rebase
, but the commit is still there, what shall I do?
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 195471c5940ef60fa1dd2ba5a52a4a6a
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File custom_include/xyz.sql is 964.43 MB; this exceeds GitHub's file size limit of 100.00 MB
回答1:
Once you have committed the large file, deleting it and committing that change will not remove it from the history.
As long as you know the full path where the file was located you can use the command below to remove the file from the commit history.
However, please be aware: this command will re-write your git history from the point at which the file you are removing was added.
git filter-branch --force --index-filter 'git rm -r --cached --ignore-unmatch [path to file to remove]' --prune-empty --tag-name-filter cat -- --all
I learnt how to do this from this excellent blog post by Ted Naleid: http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history
回答2:
If you used a git revert or removed the file and committed, that's not enough because the file will be part of the history of the branch you are trying to push anyway. You could get rid of the file on the revision where you added it by amending it (which will create a fork) and then cherry-pick all the changes that were applied on the original branch after the revision you amend.
来源:https://stackoverflow.com/questions/43547177/git-remove-commit-of-large-file