Ngresiki riwayat Git bagean 2

Data sensitif utawa konsumsi memori sing akeh banget: Ana alasan sing apik kanggo ngganti riwayat Git. Ing kirim blog iki , aku nerangake carane ngresiki file saka riwayat Git nggunakake BFG . Titik lemah BFG yaiku kekurangan dhukungan kanggo jalur langsung , mula sampeyan ora bisa mbusak file utawa folder ing subfolder saka sejarah. Kanthi mangkono, wektune golek solusi alternatif.


Saliyane cabang filter git sing ora dianjurake sacara resmi , git-filter-repo minangka salah sawijining alat kanggo ngresiki sejarah. Sawise instalasi cendhak, kita pisanan nganalisa repositori lan nemokake, contone, folder paling gedhe ing sejarah:

git filter-repo --analyze

Inggih ing folder .git/filter-repo/analysis kui kabeh limo file TXT:

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

Iku worth file directories-all-sizes.txt njupuk dipikir nyedhaki:

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

Asring kedadeyan yen sampeyan wis suwe ora nggatekake lan mbusak saka data HEAD ing sejarah (contone, folder media WordPress wp-content/uploads/ utawa sengaja di-push node_modules- utawa vendor- Pengikat).

Sing penting, platform hosting kode utama GitHub lan GitLab nyaranake pendekatan beda, sawetara kang beda-beda saka saben liyane. Contone, ing GitHub kita mbusak wp-content/uploads/ nggunakake langkah-langkah ing ngisor iki git-filter-repo saka sajarah:

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

Saiki kita uga bisa mriksa ukuran jarak jauh (ngganti ukuran liwat API lan ing UI bisa nganti 24 jam). Kanggo nindakake iki, bukak setelan repositori (yen repositori kasebut kalebu organisasi, sampeyan kudu nambah akun sampeyan dhewe ing organisasi kasebut). Saiki kita ndeleng ukuran:

GitHub: ruang disk sadurunge ngresiki
GitHub: ruang disk sawise ngresiki

Prosedur kasebut rada beda ing 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

Sawise ngenteni liyane ~ 5 menit kita bisa pindhah ing Settings > Usage Quotas ndeleng papan panyimpenan:

GitLab: ruang disk sadurunge ngresiki
GitLab: ruang disk sawise ngresiki

Sawise dibusak, penting yen kabeh pangembang sing melu melu ing langkah-langkah pungkasan: Yen pangguna saiki nindakake push normal nganggo salinan lokal dhewe, iki bakal nyebabake file gedhe bali menyang repositori tengah. Mulane, ing ngisor iki 3 opsi dianjurake:

  • rm -rf .git && git clone xxx temp && mv temp/.git ./.git && rm -rf temp && git add -A .
    ("klon seger wong miskin", kloning maneh menyang repositori sing ana)
  • rm -rf repo && git clone xxx .
    ("miwiti saka ngeruk", varian paling resik)
  • git pull -r
    ("narik karo rebase", sampeyan isih duwe sajarah najis, nanging ora sengaja nimpa maneh)

Sajrone kuota saiki (utamane amarga watesan anyar GitLab ), mesthine kudu mriksa ukuran riwayat repositori sampeyan lan ngresiki yen perlu:

GitHub GratisGitLab Gratis
Watesan ukuran file maksimal100 MB
Batas ukuran repo maksimal5.000MB
Batas count repo maksimal
Max watesan ukuran sakabèhé5.000MB

Pungkasan, sampeyan uga kudu ndeleng varian gratis sing di-host dhewe kaya Gitea . Kanthi gaweyan sethithik, sampeyan bisa dadi tuan rumah conto Git sing dadi tuan rumah dhewe (GUI sing diamanake SSL , kalebu serep , kontrol liwat API sing kuat ) ing server sing ramping banget , sing uga bisa dikonfigurasi kanthi apik lan uga unggul babagan proteksi data.

Bali