假设您有master
和develop
个分支机构。更进一步,假设您的工作流程是这样的:
develop
您签出了新的feature
分支机构; develop
; feature
分支与--no-ff
合并。通过这种方式,您可以很好地了解哪些提交属于哪个功能。
* Merge branch 'feature' into develop
|\
| * Commit 3
| * Commit 2
| * Commit 1
|/
* Some old commit
在某些时候,你拉master
并想要在其上重新develop
。但是,在rebase git log
以线性方式显示develop
上的所有提交之后,没有显示feature
分支并省略通用合并提交:
* Commit 3
* Commit 2
* Commit 1
* Some old commit
为什么会这样,如何在变基后保留它们?
答案 0 :(得分:3)
在Git 2.18之前,将-p
传递给git rebase
到preserve merges:
-p
--preserve-merges
Instead of ignoring merges, try to recreate them.
This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below).
使用Git 2.18,使用-r
到rebase merges:
-r
--rebase-merges[=(rebase-cousins|no-rebase-cousins)]
By default, a rebase will simply drop merge commits from the todo list, and put the rebased commits into a single, linear branch. With --rebase-merges, the rebase will instead try to preserve the branching structure within the commits that are to be rebased, by recreating the merge commits. Any resolved merge conflicts or manual amendments in these merge commits will have to be resolved/re-applied manually.
此选项不再受交互式rebase的上述限制,并且“可以随意重新排序,插入和删除提交”。