Nadiifi taariikhda Git qaybta 2

Xog xasaasi ah ama isticmaalka xusuusta oo aad u badan: Waxaa jira sababo wanaagsan oo lagu doonayo in la beddelo taariikhda Git. Boostada blog-ga , waxaan ku sharaxay sida loo nadiifiyo faylasha taariikhda Git iyadoo la adeegsanayo BFG . Meesha daciifka ah ee BFG waa taageero la'aanta waddooyinka tooska ah , markaa si gaar ah kama saari kartid faylasha ama faylalka ku jira fayl-hoosaadyada taariikhda. Taas, waa waqtigii la eegi lahaa xalal kale.


Marka lagu daro laanta miiraha git ee aan si rasmi ah loogu talin , git-filter-repo waa mid ka mid ah qalabka lagu nadiifiyo taariikhda. Ka dib markii la rakibo gaaban, waxaan marka hore falanqeyneynaa kaydka oo aan helnaa, tusaale ahaan, galka ugu weyn taariikhda:

git filter-repo --analyze

Waa hagaag gal gal .git/filter-repo/analysis soo saaray dhammaan noocyada faylalka TXT:

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

Way mudan tahay faylka directories-all-sizes.txt si dhow u fiirso:

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

Badanaa waxay dhacdaa in aad muddo dheer iska indho-tirtay oo aad ka saartay xogta HEAD ee taariikhda (tusaale, galka warbaahinta WordPress wp-content/uploads/ ama mid si lama filaan ah loo riixay node_modules- ama vendor-Binder).

Muhiimad ahaan, meelaha ugu weyn ee martigelinta koodka GitHub iyo GitLab ku talin habab kala duwan, kuwaas oo qaarkood ka duwan midba midka kale. Tusaale ahaan, GitHub waxaan ka saareynaa wp-content/uploads/ iyadoo la adeegsanayo tillaabooyinka soo socda git-filter-repo laga bilaabo taariikhda:

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
mv /tmp/config-backup .git/config
git push origin --force --all
git push origin --force --tags
# check size locally
git gc && git count-objects -vH
cd ..
rm -rf tmp-repo

Waxaan hadda sidoo kale ka hubin karnaa cabbirka meel fog (beddelka cabbirka API iyo gudaha UI waxay qaadan kartaa ilaa 24 saacadood). Si tan loo sameeyo, fur goobaha kaydka (haddii kaydka uu leeyahay urur, waa inaad marka hore ku dartaa akoonkaaga ururka). Hadda waxaan aragnaa cabbirka:

GitHub: meel bannaan oo disk ah ka hor nadiifinta
GitHub: meel bannaan oo disk ah ka dib nadiifinta

Nidaamku wax yar ayuu kaga duwan yahay GitLab:

mkdir tmp-repo
cd tmp-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 on main/master"
cd ./../../
rm -rf tmp-repo
date
# wait 30 minutes (😱)
date
# Settings > Repository > upload /tmp/commit-map-X

Sugitaan kale oo ~ 5 daqiiqo ah ka dib waan hoos geli karnaa Settings > Usage Quotas fiiri booska kaydinta:

GitLab: meel bannaan oo disk ah ka hor nadiifinta
GitLab: meel bannaan oo disk ah ka dib nadiifinta

Ka saarista ka dib, waxaa muhiim ah in dhammaan horumariyayaasha ku lugta leh ay ku lug yeeshaan tallaabooyinka ugu dambeeya: Haddii isticmaaluhu hadda sameeyo riixitaan caadi ah oo wata nuqulkooda maxalliga ah, tani waxay keeni doontaa in faylasha waaweyni ay dib ugu noqdaan kaydka dhexe. Sidaa darteed, 3 doorasho ee soo socda ayaa lagu talinayaa:

  • rm -rf .git && git clone xxx temp && mv temp/.git ./.git && rm -rf temp && git add -A .
    ("Xloon cusub oo nin faqiir ah", dib-u-deji kaydka jira)
  • rm -rf repo && git clone xxx .
    ("ka bilow xoq", kala duwanaanshaha ugu nadiifsan)
  • git pull -r
    ("jiid dib-u-dhigis", waxaad weli haysaa taariikhda aan nadiifka ahayn, laakiin hadda si lama filaan ah uma qorin)

Inta lagu jiro kootada hadda jirta (gaar ahaan iyadoo ay ugu wacan tahay xannibaadaha cusub ee GitLab ), had iyo jeer waxaa habboon in la hubiyo cabbirka taariikhda bakhaarkaaga oo aad nadiifiso haddii loo baahdo:

GitHub BilaashGitLab bilaash ah
Xadka cabbirka ugu badan ee faylka100MB
Xadka cabbirka ugu badan ee repo5,000MB
Xadka ugu badan ee tirinta repo
Xadka cabbirka guud ee ugu badan5,000MB

Ugu dambayntii, waxa kale oo mudan in la eego is-martigeliyay, kala duwanaanshiyaha bilaashka ah sida Gitea . Dadaal yar, waxaad martigelin kartaa tusaale Git ah oo iskiis u shaqeya (GUI oo lagu xafiday SSL , kaabaynta lagu daray, kantaroolka iyada oo la adeegsanayo API awood leh ) oo ku yaal server aad u caato ah , kaas oo sidoo kale loo habayn karo si aad u wanaagsan oo sidoo kale ka sarreeya xagga ilaalinta xogta.

Dib u laabo