[Git] 原來 git stash save 已經被棄用了

[Git] 原來 git stash save 已經被棄用了

今天臨時要修改一個檔案,先用 git status 看一下目前的狀況:

testuser@localhost $ git status

On branch master
Changes not staged for commit:
    modified:   manifest.json
    modified:   mvc_model.js
    modified:   mvc_view.js
    modified:   popup.js
    modified:   version_changes_history.js

Untracked files:
    decode_error_report.py
    error_report.txt

 

嗯… 我要改的檔案就是 mvc_view.js,

但這檔案目前被我改到一半…

記起來之前用 git stash 命令暫存目前的修改工作

不過因為 git stash -h 裡面,我看到了另一個 git stash save,

以為應該用這個指令,就執行了如下的指令:

testuser@localhost $ git stash save mvc_view.js

Saved working directory and index state On master: mvc_view.js

 

看起來好像也是有暫存,

不過用 git status 一看,所有修改中的檔案都被還原成未修改狀態…

雖然我有在 git stash save 後面指定 mvc_view.js,

但看起來 git stash save 並不理會它:

testuser@localhost $ git status

On branch master
Untracked files:
    decode_error_report.py
    error_report.txt

 

仔細看了一下 git stash 的說明網頁

原來 git stash save 不支援指定檔案,而且已經被棄用了,

建議使用 git stash push (或是 git stash 也是等於 git stash push)~

 

先用 git stash pop 將檔案從暫存庫還原回來:

git stash pop

 

這次改用 git stash push:

testuser@localhost $ git stash push mvc_view.js

Saved working directory and index state WIP on master: 1d191b9 Add 3.65 packages

 

這時確實只有指定的 mvc_view.js 被放進暫存庫,

檔案內容被還原成未修改的狀態了:

testuser@localhost $ git status

On branch master
Changes not staged for commit:
    modified:   manifest.json
    modified:   mvc_model.js
    modified:   version_changes_history.js

Untracked files:
    decode_error_report.py
    error_report.txt

 

不過 git stash save 的訊息看起來和 git stash push 大同小異,

不知道為什麼不寫出像 deprecated 之類的警告訊息,

以免誤用了而不自知…

 

參考資料:stackoverflow: how can I git stash a specific file?

(本頁面已被瀏覽過 2,439 次)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料