1. 起首先提交多次记载
在log中可以看到有多次commit 记载
然后拉取最新代码
- (base) ➜ gaolijie git:(master) git pull --rebase origin master
- From https://gitee.com/Blue_Pepsi_Cola/gaolijie
- * branch master -> FETCH_HEAD
- Already up to date.
复制代码 执行归并代码
- (base) ➜ gaolijie git:(master) git rebase -i HEAD~3
复制代码 执行了 rebase 之后会弹出一个窗口,让你选择归并哪些 commit 记载
- pick 3ca6ec3 '注释**********'
- pick 1b40566 '注释*********'
- pick 53f244a '注释**********'
复制代码 需要把 pick 改为 s 或 squash,需要留第一个,第一个不要改,意思是下面的 commit 记载都归并到第一个上面去。
- pick 3ca6ec3 '注释**********'
- s 1b40566 '注释*********'
- s 53f244a '注释**********'
复制代码 生存退出
如果有冲突,可以先解决冲突,解决完之后执行:
- git add .
- git rebase --continue
复制代码 如果没有冲突,或者冲突已经解决,会弹出窗口,让你注释掉一些提交记载,这里是让我们编辑自己归并的这些记载的概览,如:完成了什么功能,按照实际情况填写。
- # This is a combination of 3 commits.
- # This is the 1st commit message:
- 这里是填写最新的commit
- #fix: 5
- # This is the commit message #2:
- #fix: 6
- # This is the commit message #3:
- #合并fix7 8 9
- # Please enter the commit message for your changes. Lines starting
- # with '#' will be ignored, and an empty message aborts the commit.
- #
- # Date: Sun Feb 16 18:36:08 2025 +0800
- #
- # interactive rebase in progress; onto 130579e
- # Last commands done (3 commands done):
- # squash 1fa1b57 fix: 6
- # squash f54005d 合并fix7 8 9
- # No commands remaining.
- # You are currently rebasing branch 'master' on '130579e'.
- #
- # Changes to be committed:
- # modified: README.md
复制代码
生存退出,按下 esc 再按 :然后输入 wq 或 x 生存
如图:有 Successfully rebased and updated 字样就代表归并乐成了

- (base) ➜ gaolijie git:(master) git push -f
- Enumerating objects: 5, done.
- Counting objects: 100% (5/5), done.
- Delta compression using up to 12 threads
- Compressing objects: 100% (2/2), done.
- Writing objects: 100% (3/3), 342 bytes | 342.00 KiB/s, done.
- Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
- remote: Powered by GITEE.COM [1.1.5]
- remote: Set trace flag 064712a5
- To https://gitee.com/Blue_Pepsi_Cola/gaolijie.git
- + f54005d...6950c9d master -> master (forced update)
复制代码 最后git push -f
2. 某个版本之前的commit记载归并
也可以指定归并某个版本之前的版本:git rebase -i 00c7d7ff 但不包罗 00c7d7ff,至归并他之前的。
00c7d7ff
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |