简体   繁体   中英

Git - remove commit of large file

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM