iT邦幫忙

2

Git 學習筆記_07(Git stash 暫存檔案)

簡介

在我們開發專案的時候可能目前在做一件事情,但這時候卻有更緊急的事情要處理而不得不暫時放下手中的事,可是手上的事情尚未完成無法將它加入到commit中,這時暫存檔案就非常重要了,可以將我們目前手中的事情暫時保存起來,既不用將它上傳到commmit中也不必擔心它遺失。

git stash -> 暫時儲存當前目錄

利用一個簡單的案例來模擬需要暫存檔案的環境。

Step 1 : 新增一個index.html來模擬現在手上正在處理的事情

https://ithelp.ithome.com.tw/upload/images/20200420/2012476732D3VFg1jO.png

Step 2 : 建立一個branch issue來模擬突發裝況

https://ithelp.ithome.com.tw/upload/images/20200420/201247672iBlF6Lbkx.png

Step 3 : 持續在master中處理手中事務,但issue突然需要處理,則先將master的事物暫存下來

由於master的事物還沒有處理好,無法將它加入到commit中。
https://ithelp.ithome.com.tw/upload/images/20200420/201247678sxei4wvS1.png

使用git stash將master的事物暫存起來
https://ithelp.ithome.com.tw/upload/images/20200420/20124767QpbF0aWSYW.png

Step 4 : 到issue中模擬處理緊急事務

https://ithelp.ithome.com.tw/upload/images/20200420/20124767bwzGSw0QFa.png
https://ithelp.ithome.com.tw/upload/images/20200420/20124767unI3stEQyo.png

Step 5 : 當處理完緊急狀況後,回到master繼續處理原本手頭上的事情

回到master後可以利用指令git stash pop可以回復暫存的檔案
https://ithelp.ithome.com.tw/upload/images/20200420/20124767IyCtIhGtHV.png

原本在master中暫存的index.html的程式透過git stash pop恢復了
https://ithelp.ithome.com.tw/upload/images/20200420/20124767hoqxt6FjBA.png

參考資料 :
掌握 Git 與 Github 程式時光機


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言