Skip to content

Latest commit

 

History

History
71 lines (46 loc) · 2.09 KB

README.md

File metadata and controls

71 lines (46 loc) · 2.09 KB

git-shrink

A git shrink utility command that remove all old objects from repository. It's simply a bash utility that automatizes the steps of the amazing Steve Lorek's guide : http://stevelorek.com/how-to-shrink-a-git-repository.html BE CAREFUL : undone operation, all the data removed will not be recovered. If you are not sure about these operations, pls read the guide first, and make a backup of your repo.

Getting Started

Download :

git clone https://github.com/giper45/git-shrink.git    

Then copy in your repo in order to use

Destroy max size objects in you repo

Run :

sh check_git.sh numObj 

It gives a list of top size numObj objects in your repo (default numObj = 10 ).

In order to delete all unused objects in a repo:

  • copy check_git.sh and remove_git.sh in the repo to clean .
  • run check_git.sh and save objects in local , checks if some object is important and delete from the list of files to remove.
  • call the remote script :
sh check_git.sh 100 > toremove; 
sh remove_git.sh toremove  #After the check files in toremove file, remove all objects

Repeat untile you're not satisfied about the cleaning of your repo

Completely remove objects

  • Get all the objects in your repo    
git rev-list --objects --all  > toremove
  • Modify remove_git.sh uncommenting the second for loop :
#Uncomment this for use with check_git.sh to remove max size objects
#for i in $(cat $1  | sed 1,2d  | awk '{print $4}'); do git filter-branch --tag-name-filter cat --index-filter  "git rm -r --cached --ignore-unmatch $i"   --prune-empty -f -- --all;  done; 

#Uncomment this for get the first value (to remove all the objects) 
for i in $(cat $1);    do git filter-branch --tag-name-filter cat --index-filter  "git rm -r --cached --ignore-unmatch $i"   --prune-empty -f -- --all;  done;

  • Run remove_git.sh and wait ... all objects are destroyed

After the objects' destruction

Update repo :

git push origin --force --all

License

This project is licensed under the MIT License - see the LICENSE.md file for details