ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
ဒီ exercise set က Intermediate နှင့် Advanced chapter တွေမှာ သင်ခဲ့တဲ့ branching, merging, remote collaboration, conflict resolution, နှင့် reset skill တွေကို ပေါင်းစပ်ပြီး challenge ပေးမှာ ဖြစ်ပါတယ်။ ပထမ exercise set ထက် ခက်ခဲပြီး, real project workflow နဲ့ ပိုနီးစပ်တဲ့ scenario တွေကို practice လုပ်ကြရမည်။ task တစ်ခုစီကို ပြီးအောင် လုပ်ခြင်းဖြင့် Git command line ကို confidence ရှိရှိ အသုံးပြုနိုင်ဖို့ ရည်ရွယ်ပါတယ်။
လေ့ကျင့်ခန်းများ
Task 1: existing repository တစ်ခုထဲမှာ feature/dark-mode ဆိုတဲ့ branch အသစ်ဖန်တီးပြီး, file တစ်ခုကို ပြင်ကာ commit လုပ်ပါ, ပြီးရင် main ထဲ merge ပြန်လုပ်ပါ။ Task 2: file တစ်ခုတည်းကို main branch နှင့် feature branch နှစ်ခုစလုံးမှာ line တူတူတစ်ခုကို ကွဲပြားစွာ ပြင်ပြီး, merge လုပ်တဲ့အခါ conflict ဖြစ်လာအောင် တမင်ဖန်တီးကာ, conflict ကို ဖြေရှင်းပါ။ Task 3: local repository တစ်ခုကို GitHub remote (empty repo) နှင့် ချိတ်ဆက်ပြီး, commit နှစ်ခု push လုပ်ပါ, ပြီးရင် commit တစ်ခုကို git reset --mixed ဖြင့် undo လုပ်ပြီး ပြန် commit ကာ force-push မလုပ်ဘဲ ပြန် push လုပ်နိုင်မလား စမ်းကြည့်ပါ (git push --force လိုအပ်ကြောင်း သတိပြုပါ).
Code နမူနာ
# Task 1: feature branch merge
git switch -c feature/dark-mode
echo "body { background: #111; color: #eee; }" >> style.css
git add style.css
git commit -m "Add dark mode styles"
git switch main
git merge feature/dark-mode
# Task 2: intentional conflict
git switch -c feature/header-text
# style.css line 1 ကို ပြင်ပါ, commit လုပ်ပါ
git switch main
# style.css line 1 ထပ်ကွဲပြားအောင် ပြင်ပါ, commit လုပ်ပါ
git merge feature/header-text
# CONFLICT ကို ဖွင့်ကြည့်ပြီး ဖြေရှင်းပါ
git add style.css
git commit -m "Resolve style.css conflict"
# Task 3: reset + remote sync
git remote add origin https://github.com/<your-username>/practice-repo.git
git push -u origin main
git commit -m "Bad commit to undo" --allow-empty
git reset --mixed HEAD~1
git status
git commit -m "Corrected commit"
git push origin mainTask အားလုံး ပြီးနောက် local history သည် conflict-free ဖြစ်ပြီး, GitHub remote branch သည် local main branch နှင့် အတိအကျ ကိုက်ညီနေမည်။၅ မိနစ် စမ်းကြည့်
Task 2 ကို ထပ်လုပ်ကြည့်ပြီး, ဒီတစ်ခါတော့ conflict ဖြေရှင်းရာမှာ HEAD version အစား incoming (feature) version ကိုသာ ရွေးချယ်ပြီး ဖြေရှင်းကြည့်ပါ (5 မိနစ်).
သတိလေးတစ်ချက်
remote ပေါ်တင်ပြီးသား commit ကို local မှာ reset ပြန်လုပ်ပြီးရင်, ပြန် push ဖို့ history ကွဲသွားနိုင်တဲ့အတွက် git push --force ကို team တစ်ခုနှင့် shared branch ပေါ်မှာ အလွန်သတိထားပြီး သာ သုံးပါ။