[Git] 用 git stash 命令暫存目前的修改工作,回復上次 commit 的版本
今天想要把 App 新的更新釋出了,但是有其他的東西改到一半,
不想要放進去,正好來試試 git 的 stash 功能
(一直以來我都只有用 git 的 add 和 commit :P)~
首先用 git status 看一下狀態,可以看到我有兩個檔案被修改了,還沒加到索引:
testuser@localhost ~ $ git status On branch master Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: library_taipei_city.js modified: popup.js no changes added to commit (use "git add" and/or "git commit -a")
執行 git stash 就會立刻將這兩個已經被修改的檔案,加到暫存區裡面:
testuser@localhost ~ $ git stash Saved working directory and index state WIP on master: d3f38fd Tainan library: support cancel reserved books HEAD is now at d3f38fd Tainan library: support cancel reserved books
這時再用 git status,會發現已經沒有修改中的檔案了,
去看檔案內容的話,也都回復成最後一個 commit 的狀態:
testuser@localhost ~ $ git status On branch master nothing to commit, working tree clean
這時候我就可以把我的 App 包裝好釋出啦~
之後想再取回暫存區的工作進度時,執行一下 git stash list 看有哪些暫存工作,
下面列出了一筆 (WIP 應該是 Work-In-Progress 的縮寫):
testuser@localhost ~ $ git stash list stash@{0}: WIP on master: d3f38fd Tainan library: support cancel reserved books
git stash show 可以把這個暫存工作修改到的檔案列出來:
testuser@localhost ~ $ git stash show library_taipei_city.js | 12 +++++++++--- popup.js | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-)
想繼續中斷的工作的話,下 git stash apply,
就可以將最後一筆 git stash 的記錄再取回來了:
testuser@localhost ~ $ git stash apply On branch master Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: library_taipei_city.js modified: popup.js no changes added to commit (use "git add" and/or "git commit -a")
git 的命令終於又多會用一個啦~
(本頁面已被瀏覽過 1,345 次)