Last active
February 17, 2023 23:04
-
-
Save UniIsland/7970560 to your computer and use it in GitHub Desktop.
find and remove large file from git history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135207 columns/static/img/ggj/c1.png | |
122010 columns/static/img/ggj/c2.png | |
144015 columns/static/img/ggj/c3.png | |
121790 sites/management/commands/invitation_code.txt | |
121795 sites/management/commands/invitation_code.txt | |
121800 sites/management/commands/invitation_code.txt | |
121805 sites/management/commands/invitation_code.txt | |
210125 sites/static/img/1.jpg | |
131079 sites/static/img/2.jpg | |
109902 sites/static/img/2011-ggj/daminghu.png | |
123211 sites/static/img/2011-ggj/duanqiao.png | |
144189 sites/static/img/2011-ggj/emeishan.png | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## use "cut -c54-" to find files larger than 1MB | |
## use "cut -c55-" to find files larger than 100KB | |
git rev-list --all | while read rev; do git ls-tree -lr $rev | cut -c54- | grep -v '^ '; done | sort -u | sort -k 2 > /tmp/files.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inspired by: | |
http://blog.jessitron.com/2013/08/finding-and-removing-large-files-in-git.html | |
http://stackoverflow.com/questions/8740187/git-how-to-remove-file-from-historical-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git filter-branch --index-filter \ | |
'git rm --cached --ignore-unmatch path/to/large_files' \ | |
--tag-name-filter cat -- --all | |
rm -Rf .git/refs/original | |
git gc --aggressive --prune=now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment