觀念
- git stash
可以將尚未commit的改動用git stash
git stash pop
讀取
如此一來這些沒commit的改動就不會在切換branch時影響到其他branch
練習
git stash
當我們在master commit
master.txt:
first line , committed on master
接下來建立branch other 並且切過去創檔案 other.txt但沒有commit
other.txt:
first line , forgot to commit on other
這時切回去master查看狀態,會看到不想要的結果
這時我們切回other commit other.txt但是修改master.txt內容
master.txt:
over wrote by other
沒有commit 切回master ,這時候查看會友不想到看到的狀況
現在回到other將master.txt並沒有commit:
first line , committed on master
add second line by other
使用git stash
這些尚未commit的改變會stash進去一個box中
在master/other中都看不到尚未commit的change --> 已經在stash box
接下來master.txt commit:
first line , committed on master
second line , committed on master
切到other, 此時other的master.txt仍為:
first line , committed on master
--> 我們用git stash pop
把stash box的更動改回來
master.txt:
first line , committed on master
add second line by other