(1) View the current 5 large files
git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"
(2) Remove large files from the commit record one by one
git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatch 大文件名' --prune-empty --tag-name-filter cat -- --all
(3) Completely delete
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
(4) View the size of the .git directory
du -h -d 1 .git
Resubmit
git add .
git commit -m "upload code"
git push origin master
But an error is reported: Git push error pre-receive hook declined. . . . So I checked it out. . It is caused by the protect mechanism. . . .
gitlab - Git push error pre-receive hook declined - Stack Overflow
Open your project > Settings > Repository and go to "Protected branches", find "master" branch into the list and click "Unprotect" and try again.
That's it. . . . .
finally. . . It worked. . . . .