E hoʻomaʻemaʻe i ka mōʻaukala Git ʻāpana 2

Nā ʻikepili koʻikoʻi a i ʻole ka nui o ka hoʻomanaʻo hoʻomanaʻo: Aia nā kumu maikaʻi e makemake ai e hoʻololi i ka mōʻaukala Git. Ma kēia moʻomanaʻo moʻomanaʻo , wehewehe au i ka holoi ʻana i nā faila mai ka mōʻaukala Git me ka hoʻohana ʻana iā BFG . ʻO kahi wahi nāwaliwali o BFG ʻo ka nele o ke kākoʻo no nā ala pololei , no laila ʻaʻole hiki iā ʻoe ke wehe pono i nā faila a i ʻole nā ​​waihona i loko o nā subfolders mai ka mōʻaukala. Me kēlā, ʻo ia ka manawa e nānā ai i nā hoʻonā ʻokoʻa.


Ma waho aʻe o ka lālā git filter i manaʻo ʻole ʻia , ʻo git-filter-repo kekahi o mea hana no ka hoʻomaʻemaʻe ʻana i ka mōʻaukala. Ma hope o kahi hoʻonohonoho pōkole, e nānā mua mākou i ka waihona a loaʻa, no ka laʻana, nā waihona nui loa i ka mōʻaukala:

git filter-repo --analyze

Pono i loko o ka waihona .git/filter-repo/analysis hana i nā ʻano faila TXT āpau:

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

Pono ka faila directories-all-sizes.txt e nana pono:

=== 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
...

Hoʻomaka pinepine ʻia ua lōʻihi ʻoe i nānā ʻole a wehe ʻia mai ka ʻikepili HEAD i ka mōʻaukala (no ka laʻana, ka waihona media WordPress. wp-content/uploads/ a i ʻole i hoʻokuke ʻia node_modules- a i ʻole vendor-Binder).

Manaʻo maʻamau git-filter-repo ma hope o ka hoʻomaʻemaʻe ʻana, kaomi ʻana i kahi waihona hou ʻole. Nui nā kumu i helu ʻia ma aneʻi, no ke aha kēia kūpono a pale i nā pilikia he nui. Eia nō naʻe, hiki iā ʻoe ke makemake e pana i ka waihona like a hiki nō hoʻi me kekahi mau ʻōlelo.

ʻO ka mea nui, ʻo nā kahua hoʻokipa code nui GitHub a GitLab paipai i nā ala like ʻole, ʻokoʻa kekahi o kekahi i kekahi. No ka laʻana, ma GitHub mākou e wehe wp-content/uploads/ me ka hoʻohana ʻana i kēia mau ʻanuʻu git-filter-repo mai ka mōʻaukala:

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

Hiki iā mākou ke nānā i ka nui ma kahi mamao (e hoʻololi i ka nui ma o API a ma ka UI hiki ke lawe i 24 mau hola). No ka hana ʻana i kēia, wehe i nā hoʻonohonoho waihona (inā aia ka waihona i kahi hui, pono ʻoe e hoʻohui i kāu moʻokāki ponoʻī i ka hui). I kēia manawa ʻike mākou i ka nui:

GitHub: wahi disk ma mua o ka hoʻomaʻemaʻe
GitHub: kahi diski ma hope o ka hoʻomaʻemaʻe

He ʻokoʻa iki ke kaʻina hana ma 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

Ma hope o kahi kali hou o ~ 5 mau minuke hiki iā mākou ke hele i lalo Settings > Usage Quotas nānā i kahi waiho:

GitLab: wahi disk ma mua o ka hoʻomaʻemaʻe
GitLab: wahi disk ma hope o ka hoʻomaʻemaʻe

Ma hope o ka wehe ʻia ʻana, pono e komo nā mea hoʻomohala āpau i nā pae hope loa: Inā hoʻohana ka mea hoʻohana i kēia manawa i kahi paʻi maʻamau me kā lākou kope kūloko, ʻo ia ka hopena i ka neʻe ʻana o nā faila nui i ka waihona kikowaena. No laila, ua manaʻo ʻia nā koho 3 e hiki mai ana:

  • "clone hou a ke kanaka ilihune"
    • rm -rf .git && git clone xxx temp && mv temp/.git ./.git && rm -rf temp
    • No nā faila i hoʻololi ʻia (e pili ana i ka noi): git checkout -- . a i ʻole. git add -A . && git commit -m "Push obscure file changes." && git push
  • "hoʻomaka mai ka ʻōpala"
    • rm -rf repo && git clone xxx .
  • "huki ʻino me ka rebase"
    • git pull -r
    • Aia nō iā ʻoe ka mōʻaukala haumia, akā i ka hapanui o nā hihia ʻaʻole ʻoe e hoʻopaʻa hewa hou i ka waihona mamao me ka ʻano nui kūloko.

I ka wā o nā quotas o kēia manawa (ʻoi aku ma muli o nā palena hou o GitLab ), pono mau ke nānā i ka nui o ka mōʻaukala o kāu mau waihona a hoʻomaʻemaʻe iā lākou inā pono.:

Manuahi ʻo GitHubKūʻokoʻa ʻo GitLab
Palena nui waihona100MB
Ka palena nui o ka repo5,000MB
Ka palena helu repo kiʻekiʻe
Ka palena nui holoʻokoʻa5,000MB

ʻO ka hope, pono nō hoʻi e nānā i kahi ʻano like ʻole i mālama ponoʻia Gitea e kiola. Me ka hooikaika iki e hiki ai ia oe ma a kikowaena lohi loa kahi hiʻohiʻona Git hoʻokipa ponoʻī (GUI per SSL paʻa, Kākoʻo komo, hoomalu API ikaika) hoʻokipa, he maikaʻi nō hoʻi hoʻonohonoho a ʻoi aku hoʻi ma ke ʻano o ka pale ʻikepili. Eia, ma ke ala, hiki iā ʻoe ke hoʻohana git-filter-repo E hoʻololi wale i nā waihona:

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

Eia ke kauoha sudo -u git git gc --aggressive --prune=now mea nui (ke holo nei ka cron git gc a i ʻole, ua lōʻihi loa kekahi manawa paʻi o 2 pule).

Hope