BensonLiao/blog

Git: 當stash存在多個時指定套用的stash

Opened this issue · 0 comments

如果我們有多個暫存變動
想要指定套用特定的變動
可以在popapply指定stash index:

git stash apply stash@{n}
git 2.11之後 git stash apply n

假設現在有這些變動

stash@{0}: On OOO406EE-custom-health-cs-monthly-report: monthly report stress test
stash@{1}: On OOO406EE-custom-health-cs-monthly-report: improve scrm chat input behavior
stash@{2}: WIP on use-feature-flag-to-customization: ab5a2080b feat: rollback action type select getter, use general name to render customized logo
stash@{3}: WIP on OOO3F2D1-contract-expiry-notice: a835da154 Fix:Remove debug code.
stash@{4}: WIP on OOO3F2D1-contract-expiry-notice: f8cbeeb64 Feat:ContractExpiryNoticeSerializer add organization id.
stash@{5}: WIP on locate-liff-entry-point: 7c2b0e4b1 Merge branch 'feature/scrm/locate-liff-entry-point' of github.com:beBit-tech/Omnisegment into feature/scrm/locate-liff-entry-point
stash@{6}: WIP on locate-liff-entry-point: 638de8271 refactor

我們可以下 git stash apply stash@{4}git stash apply 4
來套用上面數過來第五個暫存變動

值得一提的是 pop 在這邊就跟熟悉的 Array.pop 不一樣
pop也可以指定stash index
git同樣會套用跟移除然後更新index

比如上面的列表執行 git stash pop 1之後:

stash@{0}: On OOO406EE-custom-health-cs-monthly-report: monthly report stress test
stash@{1}: WIP on use-feature-flag-to-customization: ab5a2080b feat: rollback action type select getter, use general name to render customized logo
stash@{2}: WIP on OOO3F2D1-contract-expiry-notice: a835da154 Fix:Remove debug code.
stash@{3}: WIP on OOO3F2D1-contract-expiry-notice: f8cbeeb64 Feat:ContractExpiryNoticeSerializer add organization id.
stash@{4}: WIP on locate-liff-entry-point: 7c2b0e4b1 Merge branch 'feature/scrm/locate-liff-entry-point' of github.com:beBit-tech/Omnisegment into feature/scrm/locate-liff-entry-point
stash@{5}: WIP on locate-liff-entry-point: 638de8271 refactor

ref: https://stackoverflow.com/questions/1910082/git-stash-apply-version