恢複檔案
開發過程中,經常需要恢複删除的檔案,或者恢複到某個版本。
查詢曆史常用參數
指令 | 作用 |
git log -p | 顯示更改 |
git log --stat | 顯示每次更新的檔案修改統計資訊 |
git log --name-only | 僅在送出資訊後顯示已修改的檔案清單。 |
1.恢複到上個版本
--按時間由近及遠順序,列出所有的commit
git log
--得到上次commit的hash值,如:hash_eg
git checkout hash_eg
2.恢複到特定版本
--列出所有涉及目标檔案的commit
git log file_to_restore
--檢視某次送出的具體更改
git show [hash]
--恢複
git checkout hash_eg -- file_to_restore
分支操作
| |
git branch | 展示本地所有分支 |
git checkout -b feature_x origin/feature_x | 取遠端分支feature到本地,并建立分支feature |
git checkout --track origin/feature_x | 上面指令的簡化版 |
git branch -d test | 删除分支test |
暫存區
當你正在進行一個未完成的更改,而此時突然需要你回到上一個clean working directory時(比如取下同僚的送出,然後立即更新生産服),git stash将非常有用。注意,如果你要進行一個很大的更改,而且該更改需要多次送出,建立分支将是最好的選擇。
| |
git stash | 将目前未送出的更改儲存到暫存區,工作區恢複到上一次送出的狀态 |
git stash list | 列出暫存區的所有送出 |
git stash show {stash} | stash詳細資訊 |
git stash apply {stash} | 恢複stash |
git stash drop {} | remove a single stash |
git stash clear | clear all stash |