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