ကိုယ့် Story ကို သပ်ရပ်အောင် ပြင်ဆင်ခြင်း - git rebase အကြောင်း
git rebase
ဆိုတာဘာလဲ? ကိုယ့်ရဲ့ Story ကို ပြန်ရေးခြင်း
Section titled “git rebase ဆိုတာဘာလဲ? ကိုယ့်ရဲ့ Story ကို ပြန်ရေးခြင်း”git rebase ဆိုတာ:
- branch တစ်ခုက commits တွေကို commit အသစ်တစ်ခု အဖြစ် ပြန်လုပ်တဲ့နည်းလမ်းတစ်ခုပါ
- ကိုယ့် branch ရဲ့ စတင်တဲ့နေရာကို ပြောင်းလဲလိုက်တာဖြစ်ပါတယ်
- ကိုယ်က အခုမှ တခြားနေရာကနေ အလုပ်စခဲ့သလို ဖြစ်သွားတာပါ
- commit history ကို ပြန်ရေးတာဖြစ်ပါတယ်
အသုံးပြုပုံများ (စတင်လေ့လာသူများအတွက်):
Section titled “အသုံးပြုပုံများ (စတင်လေ့လာသူများအတွက်):”-
Local feature branch history ကို ရှင်းလင်းခြင်း:
- merging မလုပ်ခင် multiple commits တွေကို ပိုအဓိပ္ပာယ်ရှိတဲ့ commits အဖြစ် ပေါင်းစပ်ခြင်း (interactive rebase သုံးပြီး)
-
Parent branch က changes တွေကို ကိုယ့် feature branch ထဲ ထည့်သွင်းခြင်း:
- ကိုယ့် feature branch ကို up-to-date ဖြစ်အောင် ကူညီနိုင်ပြီး နောက်ဆုံး merge ကို ပိုပြီး သပ်သပ်ရပ်ရပ် ဖြစ်စေပါတယ်
Rebase (Linear Story) vs. Merge (Preserves Divergence)
Section titled “Rebase (Linear Story) vs. Merge (Preserves Divergence)”Scenario 1: ကိုယ့် Feature Branch ကို main ရဲ့ Changes များနဲ့ Update လုပ်ခြင်း
Section titled “Scenario 1: ကိုယ့် Feature Branch ကို main ရဲ့ Changes များနဲ့ Update လုပ်ခြင်း”ပြဿနာ: ကိုယ်က main ကနေ my-feature ကို ဖန်တီးခဲ့တယ်။ ကိုယ် အလုပ်လုပ်နေတုန်းမှာ main မှာ အရေးကြီး updates တွေ ရရှိခဲ့တယ်။ ကိုယ်က ဒီ updates တွေကို အခု လက်ရှိလုပ်နေတဲ့ my-feature ထဲ ထည့်သွင်းချင်တယ်။
ဘယ်လိုလုပ်မလဲ?
1. အရင်ဆုံး main ကို update လုပ်ပါ
git switch maingit pull origin main
2. my-feature ကို ပြန်ပြောင်းပါ
git switch my-feature
3. main ပေါ်မှာ Rebase လုပ်ပါ
git rebase main
ဘာဖြစ်သွားလဲ?
Git က my-feature နဲ့ သက်ဆိုင်တဲ့ commits တွေကို ခန ဘေးဖယ်ထားတယ်။ main ရဲ့ update commits တွေကို ယူပြီးတော့ ခုန က ဖယ်ထားတဲ့ my-feature ရဲ့ commits တွေကို main ရဲ့ အပေါ်မှာ တစ်ခုချင်းစီ ပြန်တင်တယ်။
Scenario 2: Interactive Rebase (git rebase -i) ဖြင့် Local Commits များကို ရှင်းလင်းခြင်း
Section titled “Scenario 2: Interactive Rebase (git rebase -i) ဖြင့် Local Commits များကို ရှင်းလင်းခြင်း”ပြဿနာ: ကိုယ့် local my-feature branch ပေါ်မှာ (push မလုပ်ခင်) ကိုယ်က "WIP"
, "fix typo"
, "another small fix"
လိုမျိုး အစီအစဉ်မကျတဲ့ commits များစွာ လုပ်ခဲ့တယ်။ Pull Request တစ်ခု မဖန်တီးခင် ဒါကို တစ်ခု၊ နှစ်ခု လောက်ပဲရှိတဲ့ သင့်တော်တဲ့ commits အဖြစ် ရှင်းလင်းချင်တယ်။
ဘယ်လိုလုပ်မလဲ? (Interactive Rebase)
git rebase -i HEAD~3
(ဒါက “လက်ရှိနေရာကနေ နောက်ဆုံး commits သုံးခုကို ပြန်ပြင်မယ် (interactive rebase)” လို့ ဆိုလိုတယ်)
ဘာဖြစ်သွားလဲ Git က ကိုယ့် သတ်မှတ်ထားတဲ့ text editor ကို commits စာရင်းနဲ့ ဖွင့်တယ်။ commit တစ်ခုချင်းစီအတွက် ကိုယ်က လုပ်ဆောင်မှု တစ်ခုကို ရွေးနိုင်တယ်:
- pick: commit ကို ရှိတဲ့အတိုင်း သုံးပါ
- reword (r): commit ကို သုံးပါ၊ ဒါပေမဲ့ message ကို ပြင်ပါ
- squash (s): ဒီ commit ရဲ့ changes တွေကို အရင် commit ထဲကို ပေါင်းထည့်ပါ၊ messages တွေကိုလည်း ပေါင်းစပ်ပါ
- fixup (f): squash နဲ့ ဆင်တူတယ်၊ ဒါပေမဲ့ ဒီ commit ရဲ့ message ကို ပယ်ဖျက်ပါ (တခြား actions တွေလည်း ရှိသေးတယ်၊ ဒါပေမဲ့ ဒါတွေက အသုံးများဆုံးပါ)

pick 37709fc WIPpick 3980a2f fix typo # ဒါကို 's' သို့မဟုတ် 'squash' လို့ ပြောင်းပါpick f259ca8 actual feature work # 'pick' ကို 'r' သို့မဟုတ် 'reword' လို့ ပြောင်းပါ