git多个commit合并
有时候我们本地写代码,因为要拉取同组其他小伙伴的代码,所以需要先把代码commit,或者当我们开发了一天,已经有了很多个commit,如果这个时候我们提交代码,其他的小伙伴使用rebase来合并你的代码。
这个时候有一种场景:A提交了10个commit,push到git,B这个时候
git fetch origin
git rebase origin/develop (如果在dev分支)
然后发现有冲突,假设A的10个commit都和B有冲突,B要先解决一个冲突,then
git rebase --continue
又有冲突,再次解决冲突,再次
git rebase --continue
几次过后,B的内心是崩溃的。。。
如果A把10次commit合并提交,B只需要解决一次冲突就可以了。
假设现在有4个commit,如下
- 073406d - (HEAD -> master) commit 3 (1 second ago) <Heath Wang>
- d765a3a - commit 2 (65 seconds ago) <Heath Wang>
- 43f4d94 - git合并 (10 minutes ago) <Heath Wang>
- fa67bb5 - 学习网站提交 (11 minutes ago) <Heath Wang>
我们将把最近的3个合并。执行如下:
git rebase -i fa67bb5
会出现如下修改:
pick 43f4d94 git合并
pick d765a3a commit 2
pick 073406d commit 3Rebase fa67bb5..073406d onto fa67bb5 (3 command(s))
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
使用squash,使用该commit,合并到上一个commit.
pick 43f4d94 git合并 #这里需要保持一个pick,其他几个合并到这个commit
s d765a3a commit 2
s 073406d commit 3Rebase fa67bb5..073406d onto fa67bb5 (3 command(s))
然后
:wq
保存退出。
这个时候最新的3个commit已经合并成一个commit。
网友评论