標籤:pos 目錄 ted commit 切換 key size tag har
假設您正在為您的產品實施的一項新功能。你的代碼是在推進開發進度而客戶不斷升級需求突然來了。正因為如此,你必須保持放下你的新功能,工作幾個小時。你不能提交你的部分代碼,也不能扔掉你的變化。所以,你需要一些臨時空間,在那裡你可以儲存你的部分修改,以便以後再提交。
在Git中,藏匿操作需要修改的追蹤檔案和階段的變化,並將其儲存在棧上未完成的更改,可以在任何時候重新。
[[email protected] project]$ git status -s M string.c ?? string
現在要切換分公司為客戶不斷升級,但你不想提交你的工作,所以你會藏匿的變化。要推一個新的藏匿到您的堆棧,運行git stash命令
[[email protected] project]$ git stash Saved working directory and index state WIP on master: e86f062 Added my_strcpy function HEAD is now at e86f062 Added my_strcpy function
現在你的工作目錄是乾淨的,所有的改變都儲存在堆棧。讓我們用git status命令驗證。
[[email protected] project]$ git status -s ?? string
現在可以安全地切換分支和做其他工作。我們可以看到的藏匿的變化列表通過使用 git stash list 命令。
[[email protected] project]$ git stash list [email protected]{0}: WIP on master: e86f062 Added my_strcpy function
假設你解決了客戶不斷升級和你要回到你的工作,已經做了一半的代碼。只要執行git stash pop 命令,它會從堆棧中刪除的變化,並把它放在當前工作目錄。
[[email protected] project]$ git status -s ?? string
[[email protected] project]$ git stash pop
上面的命令會產生以下結果。
# On branch master # Changed but not updated: # (use “git add …” to update what will be committed) # (use “git checkout — …” to discard changes in working directory) # # modified: string.c # # Untracked files: # (use “git add …” to include in what will be committed) # # string no changes added to commit (use “git add” and/or “git commit -a”) Dropped refs/[email protected]{0} (36f79dfedae4ac20e2e8558830154bd6315e72d4) [[email protected] project]$ git status -s M string.c ?? string
PS:如果您想和業內技術大牛交流的話,請加qq群(521249302)或者關注公眾 號(AskHarries),謝謝!
Git 藏匿操作