Coca imbali yeGit inxalenye yesi-2

Idatha ebuthathaka okanye ukusetyenziswa kwememori kakhulu: Kukho izizathu ezilungileyo zokufuna ukutshintsha imbali yeGit. Kule post yebhlog , ndachaza indlela yokucoca iifayile kwimbali yeGit usebenzisa iBFG . Inqaku elibuthathaka le-BFG kukunqongophala kwenkxaso yeendlela ezithe ngqo , ngoko awukwazi ukususa ngokuthe ngqo iifayile okanye iifolda kwiifolda ezisezantsi ukusuka kwimbali. Ngaloo nto, lixesha lokujonga ezinye izisombululo.


Ukongeza kwisebe le- git filter engacetyiswanga ngokusemthethweni , i-git-filter-repo sesinye sezixhobo zokucoca imbali. Emva kokufakela okufutshane , siqala sihlalutya indawo yokugcina kwaye sifumane, umzekelo, iifolda ezinkulu kwimbali:

git filter-repo --analyze

Ewe, yiba kwifolda .git/filter-repo/analysis kwenziwe zonke iintlobo zeefayile zeTXT:

  • directories-all-sizes.txt
  • extensions-all-sizes.txt
  • path-all-sizes.txt
  • ...

Ifanelekile ifayile directories-all-sizes.txt jonga ngakumbi:

=== All directories by reverse size ===

Format: unpacked size, packed size, date deleted, directory name

  4624417043 3796607988 <present> <toplevel>
  4475940396 3778033787 <present> wp-content
  4060236681 3694449320 <present> wp-content/uploads
   305163809   70576241 <present> wp-content/plugins
   123818107   15442735 <present> wp-includes
...

Ngokuqhelekileyo kwenzeka ukuba ude ungayinaki kwaye uyisuse kwi-HEAD data kwimbali (umzekelo, ifolda yemidiya ye-WordPress wp-content/uploads/ okanye ityhilwe ngempazamo node_modules- okanye vendor-Binder).

Icebisa ngokubanzi git-filter-repo emva kokucoca, ukutyhala kwindawo entsha, engenanto yokugcina. Kukho izizathu ezininzi ezidweliswe apha, kutheni oku kunengqiqo kwaye kuphephe iingxaki ezininzi. Nangona kunjalo, kuyenzeka ukuba ufune ukutyhala kwindawo yogcino olufanayo kwaye oko kunokwenzeka ngeengcebiso ezimbalwa.

Okubalulekileyo, iiplatifti ezinkulu zokubamba ikhowudi GitHub kwaye GitLab cebisa iindlela ezahlukeneyo zokujonga, ezinye zazo zahluke enye kwenye. Umzekelo, kwi-GitHub siyayisusa wp-content/uploads/ usebenzisa la manyathelo alandelayo git-filter-repo ukusuka kwimbali:

mkdir tmp-repo
cd tmp-repo
git clone git@github.com:foo/bar.git .
cp .git/config /tmp/config-backup
git filter-repo --invert-paths --path wp-content/uploads/
# option 1: same repo
  mv /tmp/config-backup .git/config
  git push origin --force --all
# option 2: new repo
  git remote add origin git@github.com:foo/bar-new.git
  git push origin --force --all
cd ..
rm -rf tmp-repo

Ngoku sinokujonga ubungakanani ukude (ukutshintsha ubungakanani nge-API kunye ne-UI kunokuthatha ukuya kwiiyure ezingama-24). Ukwenza oku, vula izicwangciso zokugcina (ukuba i-repository yeyentlangano, kufuneka uqale ungeze i-akhawunti yakho kumbutho). Ngoku sibona ubukhulu:

I-GitHub: indawo yedisk ngaphambi kokucoca
I-GitHub: indawo yedisk emva kokucoca

Inkqubo yahluke kancinane kwi-GitLab:

mkdir tmp-repo
cd tmp-repo
# option 1: same repo
  # Settings > General > Advanced > Export project > download tar.gz file into tmp-repo
  tar xzf 20*.tar.gz
  git clone --bare --mirror project.bundle
  cd project.git
  git filter-repo --invert-paths --path wp-content/uploads/
  cp ./filter-repo/commit-map /tmp/commit-map-1
  # copying the commit-map has to be done after every single command from git filter-repo
  # you need the commit-map files later
  git remote remove origin
  git remote add origin git@gitlab.com:foo/bar.git
  # Settings > Repository > Protected branches/Protected branches >
  # enable "Allowed to force push to main/master"
  git push origin --force 'refs/heads/*'
  git push origin --force 'refs/tags/*'
  git push origin --force 'refs/replace/*'
  # Settings > Repository > Protected branches/Protected branches >
  # disable "Allowed to force push to main/master"
  date
  # wait 30 minutes (😱)
  date
  # Settings > Repository > upload /tmp/commit-map-X
# option 2: new repo
  git clone git@gitlab.com:foo/bar.git .
  git filter-repo --invert-paths --path wp-content/uploads/
  git remote add origin git@gitlab.com:foo/bar-new.git
  # Settings > Repository > Protected branches/Protected branches >
  # enable "Allowed to force push to main/master"
  git push origin --force --all
  # Settings > Repository > Protected branches/Protected branches >
  # disable "Allowed to force push to main/master"
cd ..
rm -rf tmp-repo

Emva kokulinda okunye malunga nemizuzu emi-5 sinokungena ngaphantsi Settings > Usage Quotas jonga indawo yokugcina:

I-GitLab: indawo yedisk phambi kokucoca
I-GitLab: indawo yedisk emva kokucoca

Emva kokususwa, kubalulekile ukuba bonke abaphuhlisi ababandakanyekayo babandakanyeke kumanyathelo okugqibela: Ukuba umsebenzisi ngoku wenza utyhala oluqhelekileyo ngekopi yakhe yendawo, oku kuya kubangela ukuba iifayile ezinkulu zifudukele emva kwindawo yokugcina. Ngoko ke, ezi zikhetho ze-3 zilandelayo ziyacetyiswa:

  • "iklone entsha yehlwempu"
    • rm -rf .git && git clone xxx temp && mv temp/.git ./.git && rm -rf temp
    • Kwiifayile ezitshintshiweyo (kuxhomekeke kwisicelo): git checkout -- . okanye. git add -A . && git commit -m "Push obscure file changes." && git push
  • "qala ukusuka ekuqaleni"
    • rm -rf repo && git clone xxx .
  • "utsalo olubi kunye ne-rebase"
    • git pull -r
    • Apha usenayo imbali engacocekanga, kodwa kwiimeko ezininzi awusayibhala ngempazamo indawo yokugcina ekude ngokwahluka okukhulu kwendawo.

Ngexesha lezabelo zangoku (ingakumbi ngenxa yezithintelo ezitsha zeGitLab ), kuhlala kufanelekile ukujonga ubungakanani bembali yogcino lwakho kwaye lucocwe ukuba kuyimfuneko.:

GitHub MahalaGitLab Mahala
Ubungakanani bobungakanani bobungakanani befayile elinganiselweyo100MB
Ubungakanani bobungakanani bomlinganiselo werepo5,000MB
Ubuninzi bomlinganiselo wokubalwa kwerepo
Ubukhulu bobungakanani bomlinganiselo opheleleyo5,000MB

Okokugqibela, kufanelekile ukuba ujonge umntu ozibambayo, owahlukileyo wasimahla onje Gitea Ukujula. Ngomzamo omncinci unako kwi iseva encinci kakhulu umzekelo weGit ozibambeleyo (GUI nge I-SSL ikhuselekile, Ugcino ifakiwe, ulawulo phezu API enamandla) umamkeli, nawo agqwesileyo qwalasela kwaye iphezulu ngokubhekiselele kukhuseleko lwedatha. Apha, ngendlela, ungasebenzisa kwakhona git-filter-repo Lungisa ngokulula iindawo zokugcina:

mkdir tmp-repo
cd tmp-repo
git clone git@git.tld.com:foo/bar.git .
cp .git/config /tmp/config-backup
git filter-repo --invert-paths --path wp-content/uploads/
# option 1: same repo
  mv /tmp/config-backup .git/config
  git push origin --mirror
  # login on the remote command line and run in the repo-folder
  sudo -u git git reflog expire --expire=now --all
  sudo -u git git gc --aggressive --prune=now
  # if you face memory limit issues, modify the git configuration
  sudo -u git git config --global pack.windowMemory "100m"
  sudo -u git git config --global pack.packSizeLimit "100m"
  sudo -u git git config --global pack.threads "1"
  # if in web ui the size does not change, make a slight
  # modification to a file and push again normally
# option 2: new repo
  git remote add origin git@git.tld.com:foo/bar-new.git
  git push origin --force --all
cd ..
rm -rf tmp-repo

Nanku umyalelo ngokukodwa sudo -u git git gc --aggressive --prune=now kubalulekile (i-cron iyasebenza git gc kungenjalo inomnye omde kakhulu ixesha lokuthena kwiiveki ezi-2).

Emva