Skip to content

Instantly share code, notes, and snippets.

@nashid
Last active July 6, 2022 07:00
Show Gist options
  • Save nashid/bde27c773f949641f107a84ef77bab02 to your computer and use it in GitHub Desktop.
Save nashid/bde27c773f949641f107a84ef77bab02 to your computer and use it in GitHub Desktop.
delete large file from git history

ref: https://www.czettner.com/2015/07/16/deleting-big-files-from-git-history.html

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch dev/database.sql" --prune-empty --tag-name-filter cat -- --all

git reflog expire --expire=now --all
git gc --prune=now

git push origin --force --all
git push origin --force --tags

rm -rf .git/refs/original/

git fetch
git reset origin/master --hard

# https://stackoverflow.com/questions/5613345/how-to-shrink-the-git-folder 
git repack -a -d --depth=250 --window=250

Example:

Given the large file is understand-tooling/combined-metadata.json:

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch understand-tooling/combined-metadata.json" --prune-empty --tag-name-filter cat -- --all

git reflog expire --expire=now --all
git gc --prune=now

git push origin --force --all
git push origin --force --tags

rm -rf .git/refs/original/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment