一图弄懂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到远程仓库的内容


目录
相关文章
|
2月前
|
开发工具 git
git merge和git rebase异同
git merge和git rebase异同
117 0
|
11月前
|
开发工具 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...
|
25天前
|
开发工具 git 开发者
【git merge/rebase】详解合并代码、解决冲突
【git merge/rebase】详解合并代码、解决冲突
49 0
|
2月前
|
JSON 开发工具 git
git rebase 合并当前分支的多个commit记录
git rebase 合并当前分支的多个commit记录
|
14天前
|
安全 开发工具 git
蓝易云 - git rebase和merge区别
在选择使用Merge还是Rebase时,需要根据具体的工作流程和团队的规定来决定。一般来说,如果你想保持完整的历史记录并且避免可能的冲突,你应该使用Merge。如果你想要一个干净的、线性的历史记录,你可以使用Rebase。
17 4
|
2月前
|
开发工具 git
git pull之后出现REBASE(1/1)
git pull之后出现REBASE(1/1)
44 3
|
2月前
|
开发工具 git 开发者
【专栏】探讨了 Git 中的 `git rebase` 操作,它用于重新应用提交到另一分支,改变历史顺序
【4月更文挑战第29天】本文探讨了 Git 中的 `git rebase` 操作,它用于重新应用提交到另一分支,改变历史顺序。与 `git merge` 不同,rebase 重写提交历史,提供简洁线性的历史记录。文章介绍了 rebase 的基本操作、应用场景,如整理提交历史、解决冲突和整合分支,并强调了使用注意事项,如避免在公共分支上操作。尽管 rebase 可以带来整洁的历史和冲突解决便利,但其潜在的风险和可能导致的历史混乱需谨慎对待。理解并恰当使用 `git rebase` 可以提升开发效率和代码质量。
|
2月前
|
前端开发 开发工具 git
git rebase 和 git merge的区别?以及你对它们的理解?
git rebase 和 git merge的区别?以及你对它们的理解?
84 1
|
2月前
|
开发工具 git 开发者
百度搜索:蓝易云【Git:Rebase和Merge之间的区别】
综上所述,Rebase和Merge在代码合并方面具有不同的特点和用途。根据具体的情况和个人偏好,选择适合的合并方式能够更好地管理和组织代码。
57 0
|
2月前
|
Shell 开发工具 git
git 常用命令详解(merge/rebase/cherry-pick)
git常用命令详解。 git merge将已提交的commit(自历史记录与当前分支分开以来的提交)合并到当前分支中。 rebase变基的原理 git-cherry-pick能应用(合并)已经存在的commit,即选择合并某个特定commit