一图弄懂Git rebase

简介: 两种合并分支的方式:merge,rebaseWith the rebase command, you can take all the changes that were committed on one branch and replay them on a different branch

一图弄懂Git rebase



两种合并分支的方式:merge,rebase


With the rebase command, you can take all the changes that were committed on one branch and replay them on a different branch


rebase是如何合并分支的


如下图:采用rebase方式将experiment分支上的内容合并到master分支上


20200423163412708.png


git rebase master这个命令幕后都做了什么操作:


先experiment分支的修改暂存起来

将experiment分支reset到master分支的状态

在重置后的experiment分支上replay刚刚暂存起来的修改

最后:切换到master分支,进行简单的fast-forward合并即可


为什么要用rebase(和merge的区别)

如上例中所示,rebase的提交历史更干净线性


何时(不)使用rebase

In general the way to get the best of both worlds is to rebase local changes you’ve made but haven’t shared yet before you push them in order to clean up your story, but never rebase anything you’ve pushed somewhere.


在本地开发时可以使用,让我们的提交历史更干净易读


不要使用rebase合并已经push到远程仓库的内容


目录
相关文章
|
开发工具 git
git merge和git rebase异同
git merge和git rebase异同
308 0
|
开发工具 git
成功解决git rebase问题:First, rewinding head to replay your work on top of it...
成功解决git rebase问题:First, rewinding head to replay your work on top of it...
|
6月前
|
人工智能 前端开发 Java
用git rebase命令合并开发阶段中多条commit提交记录
通过 `git rebase`,可以合并多个提交记录,使开发历史更简洁清晰。操作分为 6 步:查看提交历史 (`git log --oneline`)、设置需合并的提交数 (`git rebase -i HEAD~N`)、修改动作标识为 `s`(squash)、保存退出编辑、调整提交信息、强制推送至远程仓库 (`git push -f`)。此方法适合清理本地无关提交,但若有团队协作或冲突风险,需谨慎使用以避免问题。
785 60
|
7月前
|
开发工具 git
git的rebase和merge的区别
通过这些内容和示例,您可以深入理解Git的 `rebase`和 `merge`操作及其区别,选择合适的方法进行分支管理,提高版本控制的效率和规范性。希望这些内容对您的学习和工作有所帮助。
1063 5
|
9月前
|
开发工具 git 开发者
git rebase的使用
通过这些思维导图和分析说明表,您可以更直观地理解Git rebase的概念、用法和应用场景。希望本文能帮助您更高效地使用Git rebase,提高代码管理的效率和质量。
869 17
|
JSON 开发工具 git
git rebase 合并当前分支的多个commit记录
git rebase 合并当前分支的多个commit记录
425 1
|
9月前
|
开发工具 git 开发者
git rebase的使用
通过这些思维导图和分析说明表,您可以更直观地理解Git rebase的概念、用法和应用场景。希望本文能帮助您更高效地使用Git rebase,提高代码管理的效率和质量。
1305 13
|
开发工具 git 开发者
【git merge/rebase】详解合并代码、解决冲突
【git merge/rebase】详解合并代码、解决冲突
2109 0
|
10月前
|
前端开发 持续交付 开发工具
理解前端开发中的 Git - Rebase
Git Rebase 是前端开发中常用的一种版本控制操作,用于将一个分支的更改整合到另一个分支。与合并(Merge)不同,Rebase 可以使提交历史更加线性整洁,有助于保持代码库的清晰和可维护性。通过 Rebase,开发者可以将特性分支的改动应用到主分支上,同时保留或重写提交记录。
|
开发工具 git 开发者