git bisect
git
用法
git bisect start <bad> <good>不斷把提交區間對半切,找出第一個出問題的提交;結束時必須 git bisect reset,否則你會一直停在分離的提交上。
常用選項
| 選項 | 含義 |
|---|---|
| start <bad> <good> | begin, naming a broken and a working commit |
| good | mark the checked-out commit as working |
| bad | mark it as broken |
| skip | this commit cannot be tested |
| run <cmd> | let a command decide by its exit code |
| reset | stop and go back to where you were |
範例
git bisect start HEAD v1.1.0starts the search between the last release and now
git bisect run npm testfinds the first failing commit with no further input
git bisect resetends the session; skipping this leaves you on a detached commit
難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. git bisect 是做什麼的?
不斷把提交區間對半切,找出第一個出問題的提交;結束時必須 git bisect reset,否則你會一直停在分離的提交上。
Q. 怎麼寫?
git bisect start <bad> <good> —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 6 個,完整列表在 man git。這條命令屬於git。
相關命令
man 手冊: man git-bisect