rebase
git pull --no-rebase
查看git提交记录
git log --oneline
远程分支commit id记录
1.1bcbdeb
2.2940791
3.929d814
4.81f85a0
本地分支commit id记录
1.5b966bb
2.2940791
3.929d814
4.81f85a0
执行合并命令: git pull --no-rebase,如果有冲突,需要先解决后在合并
1.211a855
2.5b966bb
3.1bcbdeb
4.2940791
5.929d814
可以看出git pull --no-rebase,会保留远程分支(commit id:1bcbdeb)和本地分支(commit id:5b966bb)最新的commit id,会将远程分支的commit id当做本地分支commit id父id,然后发起一次新的合并请求(commit id:211a855)
git pull --rebase
远程分支commit id记录
1.c07bffa
2.211a855
3.5b966bb
4.1bcbdeb
本地分支commit id记录
1.870ceda
2.211a855
3.5b966bb
4.1bcbdeb
执行合并命令: git pull -rebase,如果有冲突,需要解决
3d8b71a (HEAD) merge remote2
c07bffa (origin/rebase_test) remote update2
211a855 merge remote
5b966bb local update
1bcbdeb remote update
可以看出 git pull -rebase后,会保留远程分支记录(commit id:c07bffa),本地最新的提交记录(commit id:870ceda)将消失,合并后产生一个新的提交记录(commit id:3d8b71a)
注意:如果合并过程中产生冲突,解决完冲突提交后,会提示如下问题。
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
git会认为正在当前正在编辑一个commit,可以执行命令:git status查看,
interactive rebase in progress; onto 2b1c8f3
Last command done (1 command done):
pick 45a1f20 local update4
No commands remaining.
You are currently editing a commit while rebasing branch 'rebase_test' on '2b1c8f3'.
(use "git commit --amend" to amend the current commit)
(use "git rebase --continue" once you are satisfied with your changes)
还需要执行命令:git rebase --continue,完成这个commit,然后在push到远程仓库
如果想放弃这个合并,可以执行这个命令: git rebase --abort