git stash 后"本地代碼不見了"


git stash 當本地代碼不想提交覆蓋,又忙於其他分支,可以先儲存起來。

git stash命令的作用就是將目前還不想提交的但是已經修改的內容進行保存至堆棧中,后續可以在某個分支上恢復出堆棧中的內容。這也就是說,stash中的內容不僅僅可以恢復到原先開發的分支,也可以恢復到其他任意指定的分支上。git stash作用的范圍包括工作區和暫存區中的內容,也就是說沒有提交的內容都會保存至堆棧中。

git stash

存儲當前工作目錄

$ git stash
Saved working directory and index state WIP on Practice: 2f70846 Complete practice 
view and network

git stash list

查看之前存儲的所有版本列表

$ git stash list
stash@{0}: WIP on Practice: 2f70846 Complete practice view and network
stash@{1}: WIP on Practice: 2f70846 Complete practice view and network
stash@{2}: WIP on Practice: 2f70846 Complete practice view and network
stash@{3}: WIP on Practice: 2f70846 Complete practice view and network
stash@{4}: WIP on Practice: 812e77b Add collectionView and AnswerView
stash@{5}: WIP on Practice: 53bb0c1 add tableView of questions and refactor the code of scrollView

git stash pop [stash_id]

恢復具體某一次的版本,如果不指定stash_id,則默認h恢復最新的存儲進度  

$ git stash pop stash@{0}
Auto-merging WePeiYang/Shared/Network/SolaSessionManager.swift
CONFLICT (content): Merge conflict in WePeiYang/Shared/Network/SolaSessionManager.swift
Auto-merging WePeiYang/Practice/Practice/QuestionTableView/OptionsCell.swift
CONFLICT (content): Merge conflict in WePeiYang/Practice/Practice/QuestionTableView/OptionsCell.swift
Auto-merging WePeiYang/Practice/Practice/Exercise/Model/ExerciseNetwork.swift
Auto-merging WePeiYang.xcodeproj/project.pbxproj
CONFLICT (content): Merge conflict in WePeiYang.xcodeproj/project.pbxproj
恢復之后,有時打開工程文件,會發現里面所有文件都不翼而飛了?!
莫慌,莫慌
這是因為出現合並沖突的問題而導致工程文件打不開。
這時候右擊工程文件,單擊“顯示包內容”,打開“project.pbxproj”文件,然后command + f 搜索 “stashed”。把沖突部分刪掉就可以重新打開啦
 
git stash drop [stash_id]
刪除一個存儲的進度。如果不指定stash_id,則默認刪除最新的存儲進度。
 
git stash clear
清除所有的存儲進度

原文鏈接:https://www.jianshu.com/p/a634af0eb343?from=singlemessage

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM