合并多次commit记录
- 互联网
- 2025-09-09 10:48:02

合并多次commit记录 1. 首先先提交多次记录2. 某个版本之前的commit记录合并 1. 首先先提交多次记录
在log中可以看到有多次commit 记录 然后拉取最新代码
(base) ➜ gaolijie git:(master) git pull --rebase origin master From gitee /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 gitee /Blue_Pepsi_Cola/gaolijie.git + f54005d...6950c9d master -> master (forced update)最后git push -f
2. 某个版本之前的commit记录合并也可以指定合并某个版本之前的版本:git rebase -i 00c7d7ff 但不包含 00c7d7ff,至合并他之前的。 00c7d7ff
合并多次commit记录由讯客互联互联网栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“合并多次commit记录”