關於Git的stash命令

來源:互聯網
上載者:User

標籤:style   ar   color   使用   sp   for   strong   on   bs   

git stash 可用來暫存當前進行中的工作, 比如想pull 最新代碼, 又不想加新commit, 或者另外一種情況,為了fix 一個緊急的bug,  先stash, 使返回到自己上一個commit, 改完bug之後再stash pop, 繼續原來的工作。
基礎命令:
$git stash
$do some work
$git stash pop


進階:

git stash save "work in progress for foo feature"

當你多次使用’git stash’命令後,你的棧裡將充滿了未提交的代碼,這時候你會對將哪個版本應用回來有些困惑,

’git stash list’ 命令可以將當前的Git棧資訊列印出來,你只需要將找到對應的版本號碼,例如使用’git stash apply [email protected]{1}’就可以將你指定版本號碼為[email protected]{1}的工作取出來,當你將所有的棧都應用回來的時候,可以使用’git stash clear’來將棧清空。


git stash          # save uncommitted changes# pull, edit, etc.git stash list     # list stashed changes in this gitgit show [email protected]{0} # see the last stash git stash pop      # apply last stash and remove it from the listgit stash --help   # for more info

git stash: 備份當前的工作區的內容,從最近的一次提交中讀取相關內容,讓工作區保證和上次提交的內容一致。同時,將當前的工作區內容儲存到Git棧中。

 

git stash pop: 從Git棧中讀取最近一次儲存的內容,恢複工作區的相關內容。由於可能存在多個Stash的內容,所以用棧來管理,pop會從最近的一個stash中讀取內容並恢複。

 

git stash list: 顯示Git棧內的所有備份,可以利用這個列表來決定從那個地方恢複。

 

git stash clear: 清空Git棧。此時使用gitg等圖形化工具會發現,原來stash的哪些節點都消失了。

關於Git的stash命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.