2019-09-10

GIT - How to remove history for already deleted files

# Mirror the repository and get inside its directory
cd ~/Documents/mirrored_repository_name_here.git

# Display the biggest files, which might help figure out what to remove
git ls-tree -r -t -l --full-name HEAD | sort -n -k 4 | tail -n 10

# Get outside of the folder
cd ..

# Run BFG (in the desktop in this example) to delta files of a certain extension 
java -jar ~/Desktop/bfg.jar --delete-files *.zip  --no-blob-protection mirrored_repository_name_here.git

# Run BFG to delete folders
java -jar ~/Desktop/bfg.jar --delete-folders data  --no-blob-protection mirrored_repository_name_here.git

# Remove those files
git reflog expire --expire=now --all && git gc --prune=now --aggressive

# Check on the size of the repository
git count-objects -v

# Push it

git push --force



No comments:

Post a Comment