服务器是gitlab。
1. 用浏览器界面合并
点开项目,点开历史,点开某一个提交记录。
点击右上角操作按钮,下拉菜单中选择 拣选。实际上就是 cherry pick。然后选择目标 branch。勾上新建合并请求。点击拣选。就会创建合并请求。然后合并即可。
2. 用命令行合并
方法:
从 git log 中或者 gitlab 界面里找到 commit id,例如 67a98a42945257ada498c28e686a7bfb0e76f1e4。然后执行:
git cherry-pick 67a98a42945257ada498c28e686a7bfb0e76f1e4
可以一次性 cherry-pick 多个 commit id。大项目这就是给自己找麻烦,因为极容易出现冲突。一个一个 cherry-pick 就好。
执行之后果然出现冲突了。log 如下:
Auto-merging html/main2.html
Auto-merging html/main2/index.css
CONFLICT (content): Merge conflict in html/main2/index.css
error: could not apply 67a98a429... win11
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
这时候需要先解决冲突,否则下一个 cherry-pick 会报错。转到 idea,项目上右键、git,会出现 Edit Conflict。如果没有,多右键点几次,一回儿应该就会出来,毕竟控制台提示有冲突了。然后借助 idea 的界面解决冲突,保存。命令号也可以解决冲突,有界面咱就使用界面。
冲突解决完之后,会提示必须先 git commit 或者 git stash。那就先 commit 或者 stash。可以继续使用 idea 的界面来执行此操作。
执行完 commit 或者 stash 之后,可以继续下一个 cherry-pick。最后 commit、push ,就完成的指定 commit 的合并。