Git CLI ရဲ့ ဆိုးဝါးတဲ့ UX

Git ကကိုယ်တို့ software engineer တွေနေ့တိုင်းမသုံးမဖြစ်တဲ့ software တခုပဲ။ ကျေးဇူးလည်း သိပ်သိပ်ကြီးပါတယ်။ ဒါပေမယ့် Git CLI က UX ဖက်ကကြည့်ရင် တော်တော်ဆိုးဝါးပြီး ရုပ်ဆိုးလွန်းတဲ့ ဒီဇိုင်းမျိုးဆိုတာလည်း ငြင်းမရဘူး။

Git ကိုရေးတဲ့ developer (Linus Torvalds) ကိုယ်တိုင် ပြောခဲ့တာ "I'm not a nice person and I don't care about you" တဲ့။ Git ရဲ့ပြဿနာက interface တခုသေချာ သတ်မှတ်ပြီးမှ develop လုပ်ခဲ့တာမဟုတ်ပဲ internal တွေအရင်ရေးပြီးမှ နောက်က script အုပ်ပြီးထွက်လာခဲ့တာ။ initial version ကို Linus Torvalds ရေးခဲ့တာ တကယ် ၂ ပတ်ပဲကြာတယ်။

Git မှာ working directory (local filesystem), index (next commit အတွက် ဖိုင်တွေ ပြင်ဆင်မယ့်နေရာ) နဲ့ repository (commit တွေသိမ်းတဲ့နေရာ) ဆိုပြီး ၃ လွှာရှိတယ်။ ဒီ ၃ ခုကို command အမျိုးမျိုးကနေ modify လုပ်လို့ရနေတာရယ်၊ နောက်ပြီး command တခုတည်းချင်းစီမှာလည်း argument တွေ၊ flag တွေအပေါ် မူတည်ပြီး တခုထက်ပိုတဲ့ function တွေလုပ်လို့ရနေတာက Git ကိုတော်တော်ရှုပ်သွားစေတယ်။

ဥပမာ ဒီနေ့ modern ခေတ်ရဲ့ kubectl (Kubernetes client) ကိုကြည့်ရင် verb + object + identifier သွားတဲ့ pattern ကိုမြင်ရမယ်။ kubectl get pods <pod-name> --some-flags ပေါ့လေ ဆိုပါတော့။ flag တွေက ကိုယ်သုံးမယ့် command ကို enhance လုပ်ဖို့အတွက်ပဲ။ နဂိုလုပ်ဆောင်ချက် တခုလုံးကို ချိန်းပလိုက်ဖို့ မဟုတ်ဘူး။ Git ရဲ့ command တွေကတော့ဒီလိုမဟုတ်ဘူး။ command တခုတည်းမှာ function သုံးလေးခုထပ်ပြီး overload ဖြစ်နေတာတွေ အများကြီးပဲ။

git checkout က branch တခုခုကိုချိန်းတဲ့ command လို့ပဲ ကျွန်တော်တို့ အလွယ်ပြောကြတယ်။ တကယ်က checkout ဆိုတာ HEAD pointer ကိုပေးလာတဲ့ commit ဆီပြောင်းပြီး အဲ commit မှာပါတဲ့ ဖိုင်တွေကို working directory ထဲချိန်းပေးလိုက်တာပဲ။ ဒါကြောင့် git checkout main ဆိုရင် Text Editor ထဲ main branch ရဲ့ code တွေ​အဖြစ် ပြောင်းသွားတာတွေ့ရမယ်။ ဒါပေမယ့် index လို့ခေါ်တဲ့ staging area ကိုတော့ ဘာ effect မှရှိမှာ မဟုတ်ဘူး။ ဘာလို့ဆို index တို့၊ working directory တို့ဆိုတာက သီအိုရီအရ ဘယ် branch ဘယ် commit နဲ့မှမဆိုင်လို့ပဲ။

ဒါပေမယ့် ရှုပ်တာက git checkout <commit> <filename> ဆိုပြီး commit တခုခုက file တခုရဲ့ content ကိုပဲ working directory ထဲယူလာချင်တာဆိုရင် git ကတခါတည်း index ထဲပါ ထည့်ပေးလိုက်တယ်။ တကယ်လို့ အဲအချိန် git diff လို့ရိုက်ကြည့်ရင် ဘာမှပေါ်မှာ မဟုတ်ဘူး။ ဘာလို့လဲဆိုရင် working directory နဲ့ index နဲ့က အတူတူ ဖြစ်နေပြီမို့။ ဒါပေမယ့် --cached flag ထည့်ပြီး last commit နဲ့ index ကြားကွာခြားချက်ကို diff ရင်တော့ အသစ်ရောက်လာတဲ့ modification တွေကိုမြင်ရလိမ့်မယ်။ ကိုယ်မလိုချင်ဘူးဆိုရင် index ထဲရောက်လာတဲ့ file တွေကို git reset <filename> နဲ့ဖြုတ်လို့ရတယ်။ reset အကြောင်းကို နောက်မှသပ်သပ်ရှင်းပြဦးမယ်။ reset ကလည်းသိထားဖို့လိုတယ်။

နောက်ပိုင်းနှစ် Git version တွေမှာ တဖြေးဖြေး UX ဖက်ကို ပိုတွေးပြီး command တွေလိုက်ပြင်လာနေပါတယ်။ reset အစား restore တို့၊ checkout အစား switch တို့ပေါ့။ ဒါပေမယ့် Git ကအသားကျလွန်းနေတဲ့ system ဖြစ်လို့ဇွတ်ပြင်ချလိုက်လို့လည်းမရဘူး။ backward compatibility ကိုကြည့်ရသေးတယ်။ ဒီတော့ အလုပ်တခုကို command ၂ ခု ၃ ခုထပ်ပြီး ဘာသုံးလို့သုံးရမှန်းမသိ ပိုဆိုးရော။

Beginner တွေအတွက် အကြံပေးချင်တာက လက်ရှိလိုအပ်သလောက်ပဲ အရင်လေ့လာပြီး တဖြေးဖြေး ချဲ့သုံးသွားဖို့ပဲ။ ကိုယ့်ဟာကိုယ်တောင် အခုထိ Git expert ပါလို့ နည်းနည်းမှ မပြောရဲဘူး။