Tuesday, 29 May 2018

Remove Large files in Git history

You pushed some large unnecessary files mistakenly in git, then just removing the file will not help we need to remove the file from git history.

Steps to check the largest files:

- cd my-repo
- git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '/^blob/ {print substr($0,6)}' | sort --numeric-sort --key=2 --reverse | head | gcut --complement --characters=13-40 | gnumfmt --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

Steps to remove the largest files:

- Download the bfg.jar file(https://rtyley.github.io/bfg-repo-cleaner/).
- git clone --mirror git@github.com:saravanan/my-repo.git
- java -jar bfg.jar --delete-files large-file my-repo.git
- cd my-repo.git
- git reflog expire --expire=now --all && git gc --prune=now --aggressive
- git push

No comments:

Post a Comment