git merge
git
用法
git merge [--no-ff|--squash] <branch>把另一個分支的工作併進目前分支;--squash 不會留下合併記錄,所以之後 git 仍然認為那個分支沒被合併。
常用選項
| 選項 | 含義 |
|---|---|
| --no-ff | always record a merge commit, even when a fast-forward was possible |
| --ff-only | refuse unless it can fast-forward |
| --squash | stage the combined change without committing or recording a merge |
| --abort | undo a merge that stopped on conflicts |
| --continue | finish after you resolved the conflicts |
| -X ours|theirs | auto-resolve conflicting hunks one way |
| --no-commit | merge but leave the commit to you |
範例
git merge --no-ff feature/loginkeeps the branch visible in history
git merge --abortgets you back to before the conflicted merge
git merge --squash feature/loginone flat change, staged; you still have to commit
難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. git merge 是做什麼的?
把另一個分支的工作併進目前分支;--squash 不會留下合併記錄,所以之後 git 仍然認為那個分支沒被合併。
Q. 怎麼寫?
git merge [--no-ff|--squash] <branch> —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 7 個,完整列表在 man git。這條命令屬於git。
相關命令
man 手冊: man git-merge