什么是fastforward?
在提mr时经常可以看见一个提示:
Request to dev into master
fast-forward merge is not possible. Rebase the source branch onto the target branch or merge target branch into source branch to allow this merge request to be merged.
git merge
merge分为fastforward模式和no-fastforward模式
git merge 优先使用fastforward模式,加上--no-ff使用非快进模式
- 当haed到🌟满足fast-forward时:不会增加commit节点
- 当haed到🌟不满足fast-forward时,但是没有冲突时:需要写一个commit
- 当haed到🌟不满足fast-forward时,并且有冲突时:修正冲突,add暂存,然后commit,本次merge完成
git rebase
rebase变基,即改变当前节点开始分支的地方,不要在master分支上使用这个命令
使用git rebase 🌟可以将当前分支多的节点接到 🌟上,使用git rebase -i 🌟(或者是7位哈希值)可以编辑当前节点到 🌟的commit记录。
出现的pick列表是从旧到新。
- s是将本次提交添加到上一次中,
- f和s一样,但不将提交记录添加
- d是删掉本次提交,
- r是使用vim编辑提交记录,
- e是使用shell编辑提交记录
使用rebase和merge合并时出现冲突的区别
- current和incoming的所指不同
-
使用merge时,incoming是🌟(目标节点)的冲突部分,curren是当前节点的冲突部分,无论是选择哪一部分,本次merge都会成功。
-
使用rebase命令时,incoming是当前节点的冲突部分,curren是目标节点的冲突部分,current一定要保留,否则rebase失败。
- rebase不需要再次commit
-
merge命令修正冲突后需要add暂存,之后commit
-
rebase命令修正冲突后只用add暂存,然后rebase --continue,不需要commit
git pull
git pull = git fetch + git merge 🌟
git pull --rebase = git fetch + git rebase 🌟
在git pull时可能会出现的一个提示
即确认本次操作是使用的哪一种方式(merge/rebase)
其他
git reflog可以查看每一次git操作的记录。不止是有commit节点的
git log是所有commit节点
git remote -v可以查看当前仓库的远程连接
git pull 链接 名字 可以自定义远程仓库在本地的名字