Git Basic
Git Config
First Step cmd >
- git config --global user.name test (Username Add)
- git config --global user.email [email protected] (Email Add)
Git အသုံးပြုတော့မယ်ဆိုရင် Git ရဲ့ Directory လမ်းကြောင်းထဲကို ဝင်ပြီး Git Repository တည်ဆောက်ပေးရပါမယ်။ repo တည်ဆောက်တဲ့ command ကတော့ - - git init ပဲဖြစ်ပါတယ်။
git commit
Git Commit လုပ်တော့မယ်ဆိုရင် အဆင့် ၃ ဆင့်နဲ့လုပ်ဆောင်ပါတယ်။ Commit မှာလုပ်ဆောင်တဲ့ အဆင့်တွေကတော့ -
modified
staging
commited ဆိုပြီး လုပ်ဆောင်မှာဖြစ်ပါတယ်။
အပြောင်းအလဲတစ်ခုလုပ်တိုင်း modified ဖြစ်နေပီဆိုတာသိထားရမယ်။ modified လုပ်ထားတဲ့ file တွေကို commit လုပ်ပြီးသိမ်းချင်သည့်အတွက် staging အဆင့်ကိုဆက်သွားဖို့လိုပါလိမ့်မည်။ git ကို ဘယ်အဆင့်မှာရောက်နေပီလဲကြည့်ချင်တယ်ဆိုရင်တော့ terminal ကနေ git status ဆိုပီးကြည့်နိုင်ပါသည်။ ကိုယ်ရဲ့commitလေးက modified ဖြစ်နေတယ်ဆိုရင် ကိုယ့်ရဲ့ file လေးကို အနီရာင်လေးနဲ့ပြပါလိမ့်မယ်။ staging အဆင့်ကို ရောက်ပီဆိုရင်တော့ အစိမ်းရောင်လေးနဲ့ ပြနေမှာဖြစ်ပါသည်။ staging ကို add ရန် အတွက် git add index.html ကိုယ်အပ်ချင်ကြည့်ဖိုင်လေးကို ရွေးပီးထည့်နိုင်ပါသည်။ ဖိုင်တစ်ခုကို staging mode ထဲကို မှားပီးပို့မိသွားတယ်ဆိုရင် ပြန်ဖျက်ဖို့လိုမှာပဲဖြစ်ပါတယ်။ မှားပို့မိတဲ့ code တွေကိုပြန်ဖျက်ချင်တယ်ဆိုရင်တော့
git rm --cached index.html
ဆိုပီး staging mode ထဲကနေ modified mode ထဲကို ပြန်ထုတ်ချင်တဲ့ ဖိုင်လေး ကိုရွေးပေးရမှာဖြစ်ပါတယ်။
making commit
ရှိသမျှ file အကုန်လုံးကို staging mode ထဲပို့ချင်ရင် git add . ဆိုပီးအသုံးပြုနိုင်ပါတယ်။ Commit တစ်ခုကို စပြီးရေးတော့မယ်ဆိုရင် git commit -m "first commit" commit လုပ်ပြီးသားတွေကို ပြန်ကြည့်ချင်ရင်
git log ဆိုပီးကြည့်နိုင်ပါတယ်။
git log --oneline နဲ့နောက်ဆုံးထည့်ခဲ့တဲ့ code တွေကိုကြည့်နိုင်ပါတယ်။
undoing things
Commit တွေကိုအရင်အခြေအနေကို ပြန်သွားချင်ရင် အပိုင်း ၃ပိုင်းရှိပါတယ်။
checkout commit <-- သူကတော့ safe အဖြစ်ဆုံးပါ။
revert commit <-- သူလဲ safeတော့ဖြစ်ပါတယ်။ ဥပမာ တတိယမြောက်လုပ်ခဲ့တဲ commit ရဲ့ မရေးခင် အခြေအနေကိုပြန်သွားချင်တဲ့ အခါမျိုးမှာသုံးပါတယ်။ဒါမယ့် သူက ဘယ်လိုသိမ်းသွားမလဲဆိုရင် file တစ်ခုအသစ်ဆောက်ပြီးသိမ်းသွားမှာဖြစ်ပါတယ်။
rest commit <-- သူကတော့ အန္တရာယ်ရှိတယ် ဒီ commit ကိုလုံးဝဖျက်စီးပစ်လိုက်တာ၊ reset commit ကဘယ်လိုအလုပ်လုပ်လဲဆိုတော့ ဒုတိယ commit ရေးပြီးတဲ့နေရာကိုပြန်သွားချင်တယ်။
checkout commit
သွားချင်တဲ့ commit အခြေအနေကိုပြသွားချင်ရင် -
git checkout commit-id နောက်ဆုံးရေးခဲ့တဲ့ code အခြေအနေကို ပြန်သွားချင်ရင်တော့
git checkout master ဆိုပြီးတော့ ပြန်သွားနိုင်ပါတယ်။
revert commit
ဖျက်ချင်တဲ့ commit ကို safeဖြစ်ဖြစ်နဲ့ဖျက်ချင်ရင် revert commit ကိုသုံးပါတယ်။ သူကတော့ ဖျက်ထားတဲ့ အခြေအနေကို လုံးဝဖျက်စီးလိုက်တာမဟုတ်ပဲ အဲ့အခြေအနေ ကိုကိုယ်ကပြန်သွားချင်ရင်သွားလို့ရပါတယ်။ revert commit နဲ့ဖျက်လိုက်ရင် revert ဆိုပီးတော့ ဖိုင်တစ်ဖိုင်အသစ်ဆောက်သွားမှာ ဖြစ်ပါတယ်။
git revert commit-id
reset commit
commit အကုန်လုံးကို permanent အနေနဲ့ဖျက်ပစ်ချင်တယ်ဆိုရင် reset ဆိုတဲ့ commit နဲ့သုံးပါတယ်။
git reset commit-id --hard
branches
အခုလက်ရှိ ကျွန်တော်တို့ ရေးနေတဲ့ codeတွေရဲ့ commit တွေက master branch ပေါ်မှာရှိပါ တယ်။ သစ်ကိုင်းတစ်ခုနဲ့တူပါတယ်။ master branch ဆိုတာကတော့ ကျွန်တော်တို့ code တွေရဲ့ production version (or) stable ဖြစ်သွားတဲ့ version ကိုခေါ်ပါတယ်။ ရှိရှိသမျှ code တွေ commit တွေကို master branch ပေါ်မှာမတင်သင့်ပါဘူး။ အရင်ဆုံးအနေနဲ့ ကိုက testing ပဲလုပ်နေသေးတယ်ဆိုရင် branch တွေခွဲပြီးမှ အသုံးပြုသင့်ပါတယ်။ branch တစ်ခုတည်ဆောက်ချင်တိုင်း master branch ပေါ်မှာတည်ဆောက်ရပါမယ်။ branch တွေဖျက်ရင်လဲ master branch ပေါ် ကပဲဖျက်ရပါမယ်။
check branch - git branch -a
create branch - git branch test-01
change branch - git checkout test-01
create branch after change branch - git checkout -b test-02
delete branch - git branch -D test-02
merge branch to master branch
developer1 and developer2 ဆိုတယ့် branch နှစ်ခုလုံးကို master branch ကိုပေါင်း ထည့်ချင်ရင် master ကိုအရင်သွားရမယ်။
git merge user1
git merge user2
Last updated
Was this helpful?