Thuta Learning
ရှာဖွေရန်
ExercisesDevOps & Toolsbeginner

Exercise: Git အခြေခံ Commands Practice

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Exercise: Git အခြေခံ Commands Practice ကို ကိုယ်တိုင် လေ့ကျင့်ကြည့်မယ်
  • သင်ခဲ့ပြီးသား skill တွေကို practice လုပ်ပြီး ခိုင်မာအောင်လုပ်မယ်
  • အမှားရှာ၊ ပြင်တတ်၊ ကိုယ်တိုင် check လုပ်တတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

ဒီ exercise set ကတော့ Basic chapter မှာ သင်ခဲ့တဲ့ repository initialize, staging, committing, နှင့် ignoring files စတဲ့ core skill များကို quick self-test လုပ်ဖို့ ရည်ရွယ်ပါတယ်။ New concept တွေ သင်ပေးမှာမဟုတ်ဘဲ, သင်ယူထားပြီးသား command တွေကို repetition ဖြင့် ပိုမို ကျွမ်းကျင်စေမှာ ဖြစ်ပါတယ်။ task တစ်ခုစီကို terminal ဖွင့်ပြီး လက်တွေ့ run ကြည့်ဖို့ အကြံပြုပါတယ်။

လေ့ကျင့်ခန်းများ

Task 1: 'my-notes' ဆိုတဲ့ folder အသစ်တစ်ခု ဖန်တီးပြီး git init လုပ်ကာ, notes.txt ဆိုတဲ့ file တစ်ခု ဖန်တီးပြီး 'Initial notes' message နှင့် commit လုပ်ပါ။ Task 2: notes.txt ကို နောက်ထပ် line နှစ်ကြောင်း ထပ်ဖြည့်ပြီး, git diff ဖြင့် changes ကို commit မလုပ်ခင် ကြည့်ကြည့်ပါ, ပြီးမှ commit လုပ်ပါ။ Task 3: temp.log ဆိုတဲ့ file တစ်ခု ဖန်တီးပြီး, .gitignore ထဲမှာ *.log ကို ထည့်ပြီး git status ဖြင့် temp.log က track မဖြစ်ကြောင်း confirm လုပ်ပါ။ Task 4: git log --oneline ဖြင့် commit history အားလုံးကို review လုပ်ပါ။

Code နမူနာ

bash
# Task 1
mkdir my-notes
cd my-notes
git init
echo "Meeting notes" > notes.txt
git add notes.txt
git commit -m "Initial notes"

# Task 2
echo "Follow up with team" >> notes.txt
echo "Review PR by Friday" >> notes.txt
git diff
git add notes.txt
git commit -m "Add follow-up items"

# Task 3
echo "debug output" > temp.log
printf "*.log\n" >> .gitignore
git status

# Task 4
git log --oneline
You should see
Task 4 ပြီးနောက် git log --oneline မှာ commit နှစ်ခု ပေါ်လာပြီး, temp.log က git status output ထဲမှာ လုံးဝ မပါဝင်တော့ပါ။

၅ မိနစ် စမ်းကြည့်

notes.txt အစား second-notes.txt ဆိုတဲ့ file အသစ်တစ်ခု ဖန်တီးပြီး task 1-4 အားလုံးကို scratch ကနေ ပြန်ကျင့်ကြည့်ပါ (5 မိနစ်).

သတိလေးတစ်ချက်

file တစ်ခုကို တစ်ခါ git add ဖြင့် track လုပ်ပြီးသားဆိုရင် .gitignore ထဲထည့်ရုံနဲ့ untrack မဖြစ်ပါ — git rm --cached <file> ဖြင့် အရင် untrack လုပ်ရပါမည်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • git add notes.txt မလုပ်ခင် git commit ကို တိုက်ရိုက် run ပြီး 'nothing to commit' error တွေ့ခြင်း
  • .gitignore ကို ဖန်တီးထားပေမယ့် temp.log ကို .gitignore ဖန်တီးခင်က git add . နဲ့ stage လုပ်ပြီးသားဖြစ်နေလို့ track ဆက်ဖြစ်နေခြင်း

အခု ကိုယ်တိုင် စမ်းကြည့်

notes.txt အစား second-notes.txt ဆိုတဲ့ file အသစ်တစ်ခု ဖန်တီးပြီး task 1-4 အားလုံးကို scratch ကနေ ပြန်ကျင့်ကြည့်ပါ (5 မိနစ်).

You'll know it worked when: Task 4 ပြီးနောက် git log --oneline မှာ commit နှစ်ခု ပေါ်လာပြီး, temp.log က git status output ထဲမှာ လုံးဝ မပါဝင်တော့ပါ။

Exercise: Git အခြေခံ Commands Practice | Thuta Learning