Git Learning — 4
Newbie Git Notes
About Reset
[絕對定位版的reset]
command: git reset <commit#> (變成commit#)
git reset <commit#> --mixed (預設,假設共c1~c5,reset C3,則 C4、C5 會被丟到 “工作目錄”,畫面上會”隱藏” (看起來像是刪除))
git reset <commit#> --soft (C4、C5 會被丟到 “暫存區”,(跟上一部只差一個 add)),畫面上會”隱藏” (看起來像是刪除))
git reset <commit#> --hard (C4、C5 不會被丟去任何地方,畫面上會”隱藏” (看起來像是刪除))
[相對定位版]
git reset C5^:^(Caret) = -1
git reset C5^^:^^ = -2 (以此類推)
或
git reset C5~:~(tilde) = -1
git reset C5~2:~2 = -2
git reset C5~100:~100 = -100 (以此類推)
取消剛剛做完的 “合併 (merge)”
git reset HEAD^ — hard
不小心用了 reset — hard,救得回來嗎?
(1) 先用 reflog 找出要恢復的版次
git reflog = HEAD 的移動紀錄表,reference log
(2) 再下 git reset <commit#> — hard 執行,樹狀圖會合併回來,東西也都會回來
“刪除(隱藏)” 分支
git branch -d <BranchName>
error:
會提醒你此分支上未被合併(merge),
之後會變成 “Delete branch <BranchName> (was <commit#>)
i.e.
command: git branch -d dog
message: Delete branch <BranchName> (was 053fb21)
把還沒合併的分支刪掉,救得回來嗎?
git branch <NewBanchName> <commit#>
git branch new_dog 053fb21
→ 意即,原節點上建一個新分支叫new_branch,資料會跟原本的一樣
→ 注意:自己HEAD再的分支不可被刪除,要先移動HEAD才能刪分支