git delete large files

Found the notes a great God, where only address records

Great God record Address: http://www.hollischuang.com/archives/1708

 

Step 1 See which history submitted files take up more space

git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"

rev-listCommand lists submitted Git repository, we use it to list the file name and ID for all involved in the submission. The command can specify the submit only a reference (or branches) of the upstream and downstream.

--objects: The list submitted all the documents related to ID.

--all: All branches of the submission, all references to the equivalent of specifying located under refs /.

verify-packCommand displays the contents packaged.

step 2. rewrite commit, delete large files

Use the following command to delete large files submitted in history:

git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch big-file.jar' --prune-empty --tag-name-filter cat -- --all

filter-branchCommand can be used to rewrite submit Git repository

--index-filterBash parameter is used to specify a command, then Git checks out (checkout) All submissions, execute the command and resubmit.

-all parameter indicates we need to override all branches (or reference).

In the process of rewriting submitted, you will have the following log output:

Rewrite 6cdbb293d453ced07e6a07e0aa6e580e6a5538f4 (266/266) # Ref 'refs/heads/master' was rewritten

If the display  xxxxx unchanged, indicating that the file is not found in the repo, please check the path and file name are correct, repeat the above script, you want to delete all the files are deleted.

repo after step 3. Modify push

Forced to push to cover your repo, the command is as follows:

git push origin master --force

step 4. spatial cleanup and recycling

Although the above we have deleted files, but we still retained the repo inside these objects, waiting for garbage collection (GC), so we use the command to completely remove it and reclaim space command is as follows:

rm -rf .git/refs/original/ git reflog expire --expire=now --all git gc --prune=now

So far, we have completely removed the file that we do not want.

Guess you like

Origin www.cnblogs.com/weiyulin/p/12034024.html