How do I clear Java artifacts spread across many branches and commit GitHub replicas?

In the past, I accidentally made a large number of Java artifacts (.war, .jar and .class) in my GitHub repo. This led to a huge bloat of up to 100 MB. I did not notice that many commits and branches merge later.

Fortunately, there is a lot of information about this, so after endlessly trawling through the documentation of StackOverflow, GitHub and Git (thanks everyone!) I finally managed to add the following script:

#!/bin/bash echo "Removing history for *.war, *.jar, *.class files" echo "Starting size" git count-objects -v echo "Removing history for *.war, *.jar, *.class files" git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.war' --prune-empty --tag-name-filter cat -- --all git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.jar' --prune-empty --tag-name-filter cat -- --all git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.class' --prune-empty --tag-name-filter cat -- --all echo "Purging refs and garbage collection" # Purge the backups rm -Rf .git/refs/original # Force reflog to expire now (not in the default 30 days) git reflog expire --expire=now --all # Prune git gc --prune=now # Aggressive garbage collection git gc --aggressive --prune=now echo echo "Ending size (size-pack shows new size in Kb)" git count-objects -v # Can't do this in the script - it needs a human to be sure echo echo "Now use this command to force the changes into your remote repo (origin)" echo echo git push --all origin --force 

This worked perfectly in place, my 100Mb repo dropped to about 2 MB. Then i used

 git push --all origin --force 

to overwrite all branches in the GitHub repository with my local changes. Everything went well. To check everything, I deleted the local repo and cloned from GitHub. It should have been 2Mb, but again it was 100Mb.

So, after all this rambling, where did I go wrong? How to get GitHub to use my local repo with its cleared history?

Editing for more information.

The GitHub repository cannot be deleted, as it contains a lot of additional information (questions, wikis, watches, etc.). Running this script for an empty repo scratch works fine - the cloned repo is 2 MB.

The problem remains why it does not work with the main repo.

+4
source share
1 answer

It's all because of the plug

It turns out that if someone deploys your repo on GitHub, then they keep links and links to entries inside it. Therefore, your cleanup will not work if everyone who holds the plug also runs the script on their repo.

+4
source

Source: https://habr.com/ru/post/1439540/


All Articles