နားလည်ထားရမယ့် အချက်
Bug report အရေးပေါ်တစ်ခု ဝင်လာလို့ branch ချက်ချင်း ပြောင်းရမယ့်အခါ feature branch ပေါ်မှာ ပြီးစီးသေးတဲ့ uncommitted ပြောင်းလဲမှုတွေ ရှိနေတတ်ပါတယ်။ Git က overwrite ဖြစ်နိုင်ရင် branch ပြောင်းခွင့် မပြုပါဘူး။
`git stash` က working directory နဲ့ staging area ထဲက ပြောင်းလဲမှုအားလုံးကို သီးခြား storage area ထဲ ယူသိမ်းထားပြီး working directory ကို နောက်ဆုံး commit အတိုင်း ပြန်ရောက်စေပါတယ်။
- Stash က branch ဘယ်ဟာနဲ့မှ မချိတ်ဆက်ဘဲ stack တစ်ခုလို သီးခြား ရှိနေသည်
- `git stash pop` — နောက်ဆုံး stash ကို ပြန်ထည့်ပြီး stack ကနေ ဖယ်ရှားသည်
- `git stash apply` — stack ပေါ်မှာ copy ချန်ထားပြီး ပြန်ထည့်ပေးသည်
Pop မလုပ်ခင် stash အကြိမ်ကြိမ် လုပ်နိုင်ပါတယ် — stash တစ်ခုစီက stack ထဲ ထပ်ထည့်သွားပြီး `git stash list` က ဘာတွေ ဆိုင်းငံ့နေလဲ ပြပါလိမ့်မယ်။
STASH: PAUSE, SWITCH, RESUME
----------------------------
STASH: PAUSE, SWITCH, RESUME
------------------------------
working changes (uncommitted)
|
git stash
v
[ stash stack ] <- changes stored, working dir now clean
|
(switch branches, do other work)
|
git stash pop
v
working changes restored, exactly as beforeလက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Stash လုပ်ပါ
Uncommitted ပြောင်းလဲမှုတွေ ရှိနေတုန်း `git stash` run ပါ — Git က report တင်ပြီး `git status` က tree ရှင်းလင်းနေကြောင်း အတည်ပြုပါလိမ့်မယ်။
Branch ပြောင်းပါ
လိုအပ်တဲ့နေရာကို လွတ်လွတ်လပ်လပ် checkout လုပ်ပါ၊ ပြီးရင် မူလ branch ဆီ ပြန်လာပါ။
Pop ပြန်လုပ်ပါ
`git stash pop` က ပြောင်းလဲမှုတွေကို မူလအတိုင်း ပြန်ထည့်ပေးပါတယ်။
Pop က conflict ဖြစ်နိုင်ပါတယ်
Branch က ကြားထဲမှာ ပြောင်းလဲသွားရင် stash pop ဟာ merge တစ်ခုလိုပဲ conflict ဖြစ်နိုင်ပါတယ်။ Resolve မလုပ်မချင်း stash က stack ပေါ်မှာ ကျန်နေမှာဖြစ်လို့ ဘာမှ မပျောက်ပါဘူး။
အတူတူ စမ်းရေးကြည့်မယ်
git init -q -b main
git config user.name "Thuta Learner"
git config user.email "learner@example.com"
export GIT_AUTHOR_NAME="Thuta Learner"
export GIT_AUTHOR_EMAIL="learner@example.com"
export GIT_COMMITTER_NAME="Thuta Learner"
export GIT_COMMITTER_EMAIL="learner@example.com"
echo "console.log('feature in progress');" > app.js
git add app.js
GIT_AUTHOR_DATE="2026-01-06T09:00:00" GIT_COMMITTER_DATE="2026-01-06T09:00:00" \
git commit -m "Initial commit"
git branch -M main
git branch hotfix
echo "console.log('half-written feature');" >> app.js
git status
git stash
git status
git checkout hotfix
git checkout main
git stash pop
git status
cat app.js$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: app.js
no changes added to commit (use "git add" and/or "git commit -a")
$ git stash
Saved working directory and index state WIP on main: b47b383 Initial commit
$ git status
On branch main
nothing to commit, working tree clean
$ git checkout hotfix
Switched to branch 'hotfix'
$ git checkout main
Switched to branch 'main'
$ git stash pop
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: app.js
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (e9ef4229ba0e959bd1d31c7dddbe7bde3b1dd675)
$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: app.js
no changes added to commit (use "git add" and/or "git commit -a")
$ cat app.js
console.log('feature in progress');
console.log('half-written feature');၅ မိနစ် စမ်းကြည့်
Track လုပ်ထားတဲ့ file တစ်ခုကို commit မလုပ်ဘဲ ပြင်ပါ၊ ပြီးရင် `git stash` run ပြီး `git status` နဲ့ tree ရှင်းနေကြောင်း အတည်ပြုပါ။ Branch တခြားတစ်ခုကို ပြောင်းပြီး ပြန်လာပါ။ Pop မလုပ်ခင် `git stash list` ကို run ပြီး stack ပေါ်မှာ stash ဆိုင်းငံ့နေတာ ကြည့်ပါ၊ ပြီးရင် `git stash pop` run ပြီး `git diff` နဲ့ ပြောင်းလဲမှုတွေ ပြန်ရောက်နေကြောင်း အတည်ပြုပါ။
သတိလေးတစ်ချက်
`git stash` က default အနေနဲ့ staged နဲ့ unstaged ပြောင်းလဲမှုတွေကို အတူတကွ ယူသိမ်းပါတယ် — အလုပ်ရဲ့ တစ်စိတ်တစ်ပိုင်းကိုပဲ stash လုပ်ချင်ရင် plain stash အစား `git stash push -- <file>` (သို့) `git stash -p` သုံးရပါလိမ့်မယ်။
Branch က ကြားထဲမှာ ပြောင်းလဲသွားရင် stash pop လုပ်တာက merge conflict ဖြစ်စေနိုင်ပါတယ် — conflict resolve မလုပ်မချင်း (သို့) pop အောင်မြင်စွာ ပြီးဆုံးမချင်း stash က stack ကနေ ပြုတ်ကျမသွားပါဘူး။
Git Documentation: git-stash — Git & GitHub