但今天被問到為何直接修改檔案後 git pull 都會必須 stash 或 commit 時,卻答不出來
答案在 git help pull 的說明中,git pull 其實是 git fetch 再 git merge,而 merge 一定要是一個 branch,但在 working tree 內修改過的內容如果沒 commit 就不屬於這個 working tree 對應的 branch,因此 git 會警告你要先 commit (之後會 auto merge 或 conflict),或者是依我目前習慣的 git stash 暫存修改,等 git pull (主要是 merge) 之後再 git stash pop。不然可能會有遺失 work tree 修改的風險。
stash 想成是 stack 就比較容易理解,0 在最上面是 top,數字越大放在越底下表示越舊的資料,也符合一般圖解的 stack 示意圖。
習慣的動作習慣以後,本來就沒搞懂的、或遺忘細節,一被問就倒了 XD
沒有留言:
張貼留言