http://code.tutsplus.com/tutorials/rewriting-history-with-git-rebase--cms-23191

1. Rebasing for a Linear History
The first use case we'll explore involves a divergent project history.

Consider a repository where your production branch has moved forward while you were developing a feature:

To rebase the feature branch onto the master branch, you would run the following commands:
git checkout feature
git rebase master

This transplants the feature branch from its current location to the tip of the master branch:

注意下图,rebase中的base指的是某一个commit

There are two scenarios where you would want to do this.
First, if the feature relied on the new commits in master, it would now have access to them.
Second, if the feature was complete, it would now be set up for a fast-forward merge into master.
In both cases, rebasing results in a linear history, whereas git merge would result in unnecessary merge commits.

有2种情况会使用到rebase

1.如果feature分支,依赖于master分支上的新提交一系列commit【将master合并到feature】

2.如果feature分支已经完成,那么就需要将feature通过fast-forward的方式合并到master【将feature合并到master】

======使用普通的合并,无法fast-forward,会生成多余的commit====

For example, consider what would happen if you integrated the upstream commits with a merge instead of a rebase:

git checkout feature
git merge master

This would have given us an extra merge commit in the feature branch.
What's more, this would happen every time you wanted to incorporate upstream commits into your feature.

Eventually, your project history would be littered with meaningless merge commits.

第一种情况【将master合并到feature】

This same benefit can be seen when merging in the other direction.
Without a rebase, integrating the finished feature branch into master requires a merge commit.
While this is actually a meaningful merge commit (in the sense that it represents a completed feature), the resulting history is full of forks:

第二种情况【将feature合并到master】

======使用普通的合并,无法fast-forward,会生成多余的commit====

When you rebase before merging, Git is able to fast-forward master to the tip of feature.
You'll find a linear story of how your project has progressed in the git log output—the commits in feature are neatly grouped together on top of the commits in master.
This is not necessarily the case when branches are tied together with a merge commit.

Resolving Conflicts

冲突的处理可以去原文看

Rewriting History with Git Rebase的更多相关文章

  1. git rebase 的使用 (用于撤销某次commit)

    Q: I wrote the wrong thing in a commit message. Alternatively, I've forgotten to include some files. ...

  2. [译]git rebase

    rebase就是重新定义你分支的起点, 分支上的commit将生成对应的新的commit并放在你指定的新的起点commit后, 分支上的老commit将被删除. rebase就是将你的分支从一个com ...

  3. git rebase 介绍

    git rebase是对commit history的改写.当你要改写的commit history还没有被提交到远程repo的时候,也就是说,还没有与他人共享之前,commit history是你私 ...

  4. [Practical Git] Clean up commits with git rebase

    Sometimes its nice to clean up commits before merging them into your main code repo; in this lesson, ...

  5. 团队开发里频繁使用 git rebase 来保持树的整洁好吗?

    用了以后, 树可以非常清晰, 某种程度上便于追踪, 但是 push --force 就多多了,不用呢, 合并没有远程仓库被修改的麻烦, 可是追踪又不清晰... git rebase是对commit h ...

  6. git merge和git rebase的区别(转)

      Description git rebase 和 git merge 一样都是用于从一个分支获取并且合并到当前分支,但是他们采取不同的工作方式,以下面的一个工作场景说明其区别 场景:  如图所示: ...

  7. git squash 和 git rebase

    In git, what is the difference between merge --squash and rebase? 上面链接的回答中的总结: Both git merge --squa ...

  8. git rebase vs git merge详解

    https://medium.com/@porteneuve/getting-solid-at-git-rebase-vs-merge-4fa1a48c53aa#.std3ddz0g 请参考另外一篇文 ...

  9. git rebase 和 git merge 总结

    git merge 和 git rebase 都是用于合并分支,但二者是存在区别的. 在使用时,记住以下两点: 当你从 remote 去 pull 的时候,永远使用 rebase(除了一个例外) 当你 ...

随机推荐

  1. nyoj914Yougth的最大化(二分搜索 + 贪心)

    Yougth的最大化 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价值最大吗 ...

  2. ora01033 oracle正在初始化或关闭

    toad连数据库报错: ORA-01033: ORACLE initialization or shutdown in progress 解决方法: 1)开始-运行-cmd 2)命令行中输入SQLPL ...

  3. linq 多条件查询 where 拼接+分页

    首先定义一个静态类 public static class QueryAssembly { /// <summary> /// 返回true /// </summary> // ...

  4. C++类继承内存布局(二)

    转自:http://blog.csdn.net/jiangyi711/article/details/4890889# (二 )成员变量 前面介绍完了类布局,接下来考虑不同的继承方式下,访问成员变量的 ...

  5. mysql远程连接缓慢的问题

    这两天发现服务器程序启动的时候到了mysql初始连接的那一步很耗时,启动缓慢,后来发现,将连接的主机的-h参数改成localhost的时候 瞬间就完成连接了.后来在网上查到,原来是由于mysql服务器 ...

  6. 《APUE》第三章笔记(3)

    文件共享 UNIX系统支持在不同进程中共享打开的文件,首先先用一幅apue的图来介绍一下内核用于I/O文件的数据结构: 如图所见,一个进程都会有一个记录项,记录项中包含有一张打开文件描述符表,每个描述 ...

  7. Qt文件信息获取之QFileInfo

    在Qt中为文件的操作和信息获取提供了许多方便的类,常用的有QDir,QFile,QFileInfo以及QFileDialog,在本文中主要介绍用于获取关于文件信息的QFileInfo类. QFileI ...

  8. PL/SQL学习(三)游标

    原文参考:http://plsql-tutorial.com/ 两种类型:     隐式:         执行INSERT.UPDATE.DELETE 或者只返回一条结果的SELECT语句时默认创建 ...

  9. google+ 登录API 使用 javascript sdk 快速入门 (图解)

    准备工作: 打开Google API 控制台 : https://code.google.com/apis/console 点击 My Project (我的项目) 按照图示流程,您将完成一个goog ...

  10. 安装 SQL Server 2012 的硬件和软件要求(官方全面)

    以下各节列出了安装和运行 SQL Server 2012 的最低硬件和软件要求. 有关 SharePoint 集成模式下 Analysis Services 的要求的详细信息,请参阅硬件和软件要求(S ...