How to Completely Remove Deleted Secret Files and Large Files from Git History

Search for a command to run...

No comments yet. Be the first to comment.
In this series, you can learn about DevOps Tools, DevOps Tutorial and Deployment Things.
KodeKloud's 100 Days of DevOps မှာပါဝင်တဲ့ Labs တွေရဲ့ sloution တွေကို နေ့စဉ် တစ်နေ့တစ်ခု တင်ပေးသွားပါမယ်။ လိုအပ်တာတွေရှိရင်လည်း မှတ်ချက်ပေးသွားလို့ရပါတယ်။ Big thanks to KodeKloud for great free DevOps practice and letting me share the solutions! Pla...
ဒီ post လေးထဲမှာတော့ Regional NAT Gateway နဲ့ Zonal NAT Gateway ကွာခြားချက်တွေကို နှိုင်းယှဉ်ပြသွားမှာဘဲ ဖြစ်ပါတယ်။ ပထဆုံးအနေနဲ့ NAT Gateway ဆိုတာ ဘာလဲ ဘာအတွက် လိုအပ်တာလဲဆိုတာကို အရင်ပြောပြပေးပါမယ်။ P

High Level ရေးထားတာပါ ဒါပေမဲ့ လွယ်ပါတယ် ကိုယ့်မှာ AWS Infra တွေရှိတယ်ဆို တွေ့သမျှ metric တွေကို alarms တွေလုပ်ပြီး notification ယူမနေဘဲ တကယ် effective ဖြစ်တဲ့ metric တွေကိုမှ CloudWatch ရဲ့ alarm feature တွေနဲ့ ပေါင်းပြီး ပို့စေချင်ပါတယ်။ ဥပမာ prod...

ကိုယ့်ရဲ့ data center (on-prem) network နဲ့ AWS ချိတ်ဆက်ဖို့ လိုလာပြီဆိုရင် ဘယ်လို ချိတ်ဆက်ကြမလဲ? အပိုင်း (၂) မှာ တော့ Direct connect အကြောင်းကို ဆွေးနွေး သွားမှာ ဖြစ်ပါတယ်။ အပိုင်း (၁) Site-to-site VPN အကြောင်းကို လေ့လာချင်ရင်တော့ အောက်ပါ link မှာ ...

ကိုယ့်ရဲ့ data center (on-prem) network နဲ့ AWS ချိတ်ဆက်ဖို့ လိုလာပြီဆိုရင် ချိတ်ဆက်နိုင်တဲ့ နည်း (၂) နည်း ရှိပါတယ်။ 1. Site-to-Site VPN (Virtual Private Network) 2. Direct connect Site-to-Site VPN - On-prem network နဲ့ AWS resources တွေ ချိတ်ဆက်တဲ့...

လွန်ခဲ့တဲ့အပတ်က ရုံးက Designer တွေနဲ့ တော်ကီပွားရင်း Accessibility နဲ့ပတ်သတ်တာတွေ သူတို့ကို ရှင်းပြဖြစ်တယ်။ ကိုယ်တိုင်ကလည်း အရင်ကတည်းက ဒီ topic ကိုစိတ်ဝင်စားလို့ လေ့လာနေတာဆိုတော့ အခွင့်အရေးရရင် ရသလို sharing လုပ်ဖြစ်တယ်။ အဓိကက Accessibility နဲ့ပတ်သတ်...

Git ဆိုတာ အားလုံးလည်းသိကြတဲ့, အရမ်းအသုံးဝင်တဲ့ version control system တစ်ခုပဲ ဖြစ်ပါတယ်။ ဒီခေတ်မှာ git မသုံးတဲ့ developer ဆိုတာလည်း မရှိတော့သလောက်ပါပဲ။ Git repository ထဲကို ဖိုင်တစ်ဖိုင် add ပြီး commit လိုက်တာနဲ့ အဲ့ဖိုင်ကို ပြန်ဖျက်လိုက်ရင်တောင် histroy ထဲမှာ အမြဲတမ်းကျန်နေခဲ့မှာပါ။ ဒါကြောင့် git ကို time machine လို့ တစ်ချို့က တင်စားပြီးခေါ်ကြတာပါ။ ဒီအရမ်း အသုံးဝင်တဲ့ time machine ထဲကို credentials ဖိုင်တွေ (e.g: .env, private keys)နဲ့ ဖိုင်ဆိုဒ် အရမ်းကြီးပြီး repository ထဲ ထည့်စရာမလိုတဲ့ ဖိုင်တွေကို မတော်တဆ ထည့်မိရင်တော့ ပြဿနာရှိလာပါပြီ။
ဒီဆောင်းပါးမှာတော့ git history ထဲကို မတော်တဆ commit ထဲ ထည့်မိပြီးမှ ပြန်ဖျက်ထားခဲ့တဲ့ credentials ဖိုင်တွေနဲ့ file size ကြီးတဲ့ဖိုင်တွေကို အပြီးအပြတ် ဖယ်ရှားနိုင်မယ့်နည်းလမ်းတွေကို ဘယ်လို အသုံးပြုရမလဲ ပြောပြပေးသွားပါမယ်။
ဖိုင်တစ်ခုကို git rm path/to/secret.file နဲ့ ဖျက်ပြီး commit လုပ်လိုက်တာနဲ့ git history ထဲက ပျက်မသွားပါဘူး။ ဘယ်သူမဆို ဖိုင်မဖျက်ခင်အခြေအနေကို git checkout နဲ့ ပြန်သွားယူလို့ရပါတယ်။
git checkout <commit-hash> -- path/to/secret.file
ဒါကြောင့် ဒီဖိုင်ကို history ထဲက ဖျက်လိုက်ချင်ရင် ဒီဖိုင် စထည့်တဲ့ commit ကနေစပြီး git history တစ်ခုလုံးကို ပြန်ရေးဖို့လိုပါတယ်။
bfg (Repo-Cleaner)
git-sizer အသုံးပြုနိုင်ပါတယ်။# MacOS
brew install git-sizer
# Ubuntu
sudo apt install git-sizer
git-sizer
Processing blobs: 41369
Processing trees: 89219
Processing commits: 3589
Matching commits to trees: 3589
Processing annotated tags: 5
Processing references: 39
| Name | Value | Level of concern |
| ---------------------------- | --------- | ------------------------------ |
| Biggest objects | | |
| * Blobs | | |
| * Maximum size [1] | 962.0 MiB | ****** |
| | | |
| Biggest checkouts | | |
| * Maximum path depth [2] | 16 | * |
| * Maximum path length [3] | 144 B | * |
[1] cabe5dd7cf7e0c275f789bd64cc5a943a7b79acb (refs/remotes/origin/example-branch:storage/path/large-file.ext)
[2] 9a7d193d8ea79aa0a21b0a8e13310c63cb54dc83 (refs/remotes/origin/example-branch^{tree})
[3] 600bc870aee0d3e4a97f592c8fd4b92edbf70ab4 (7ac90183211e4e4832650b03fa296773e5002ca8^{tree})
git-sizer ကို သုံးပြီး ဘယ် commits တွေကြီးနေတယ်၊ ဘယ်ဖိုင်အကြီးတွေ history ထဲပါနေတယ် ဆိုတာတွေကို သိရှိနိုင်ပါတယ်။ git repo size ကြီးအောင် ဘယ်ကောင်တွေက နေရာယူနေလဲ သိပြီဆိုရင်၊ အဲ့ဖိုင်တွေကို history ထဲကနေ အောက်ပါ နည်းလမ်းတွေသုံးပြီး ဖျက်လို့ရပါတယ်။
git filter-repobrew install git-filter-repo
# or
pipx install git-filter-repo
filter-repo ကို install လုပ်ပြီးပြီဆိုရင်တော့ တစ်ဖိုင်ခြင်းဖြစ်စေ၊ တစ်ဖိုင်ထက် ပိုပြီးတော့ဖြစ်စေ ရှင်းနိုင်သလို။ extension နဲ့လည်း history ထဲက ရှင်းလိုက်လို့ရပါပြီ။
git filter-repo --path .env --invert-paths
Multiple files:
git filter-repo --path .env --path secrets.json --invert-paths
By extension:
git filter-repo --path-glob '*.zip' --invert-paths
filter-repo ထက်စာရင် bfg က သုံးရတာ ပိုလွယ်ပါတယ်။ --delete-files option ကို သုံးပြီး ရှင်းကြသလို --strip-blobs-bigger-than option ကိုသုံးပြီးလည်း file size limit နဲ့လည်း ရှင်းလို့ရပါတယ်
brew install bfg
# Remove sensitive files
bfg --delete-files .env
# Remove blobs bigger than 100MB
bfg --strip-blobs-bigger-than 100M
History ထဲကနေ ဖျက်ပြီးပြီဆိုရင်တော့ မလိုတော့တဲ့ reflog တွေကို ဖျက်ပစ်ပြီး၊ မသုံးတော့တဲ့ object တွေကို ဖျက်ပစ်ဖို့ အောက်က command တွေ run ပေးဖို့လိုက်ရင်တော့ git history ထဲက ဖိုင်အကြီးတွေ မရှိတော့တဲ့အတွက် .git folder size က အများကြီး ကျသွားတာကို တွေ့ရပါလိမ့်မယ်။
git reflog expire --expire=now --all
git gc --prune=now --aggressive
git push --force-with-lease
ပြီးရင်တော့ force pushing နဲ့ပြန်တင်ပေးဖို့လိုသလို collaborators တွေကလည်း repo ကို ဖျက်ပြီး clone ပြန်လုပ်တာဖြစ်စေ hard reset လုပ်တာဖြစ်စေ လုပ်ပေးဖို့လိုပါတယ်။
ဒါတွေကို မလုပ်ခင်မှာ repository backup လုပ်ထားသင့်ပါတယ်။
ဒီလိုမျိုးတွေ နောက်တစ်ခါ commit မလုပ်မိအောင် .gitignore ထဲမှာ ထည်ပေးထားသင့်ပါတယ်။
file အကြီးတွေ history ထဲပါနေလား သိရအောင် weekly လောက်ဖြစ်ဖြစ် git-sizer နဲ့ ပုံမှန် စစ်ပေးသင့်ပါတယ်
အဆုံးအထိ ဖတ်ပေးလို့ ကျေးဇူးတင်ပါတယ်။