git branch
git
用法
git branch [-a|-vv] [-d <name>]在本機列出、建立和刪除分支;刪掉本機的不會動遠端,伺服器那邊還要 git push origin --delete。
常用選項
| 選項 | 含義 |
|---|---|
| -a | local and remote-tracking branches |
| -r | remote-tracking branches only |
| -vv | last commit and upstream of each branch |
| -d <name> | delete a branch that is already merged |
| -D <name> | delete it even if unmerged; those commits are left behind |
| -m <old> <new> | rename |
| --merged | branches already contained in the current one |
| --show-current | print the branch you are on |
範例
git branch -vvevery local branch with its upstream and last commit
git branch -d old-featureremoves a merged branch locally only
git push origin --delete old-featurethe separate step that removes it on the server
難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. git branch 是做什麼的?
在本機列出、建立和刪除分支;刪掉本機的不會動遠端,伺服器那邊還要 git push origin --delete。
Q. 怎麼寫?
git branch [-a|-vv] [-d <name>] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 8 個,完整列表在 man git。這條命令屬於git。
相關命令
man 手冊: man git-branch