前言
這篇要記錄一下,我自己開發時遇到的情況題,
如果忘記事先切 branch,卻有新的 commit 該怎麼辦?
在多人協作時,通常我們會希望每一個功能都提交到指定的 branch 上,
因此當如果 commit 沒有在 branch 上卻有 commit,的確有點困擾啊….
解決方法
其實只要一些操作就沒有什麼困難的! 重點在活用「git stash」!
step 1. git stash 暫存此 commit
git stash save "some msgs"
step 2. 切換回你要更新的 branch
git checkout <your_branch>
step 3. apply 剛剛的 stash
git stash apply # 不移除 stash
# or
git stash pop # 移除 stash
step 4. 可以回到在該 branch 上 commit 的動作啦!
git commit -m "your msg"