Rewriting History with Git Rebase
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的更多相关文章
- git rebase 的使用 (用于撤销某次commit)
Q: I wrote the wrong thing in a commit message. Alternatively, I've forgotten to include some files. ...
- [译]git rebase
rebase就是重新定义你分支的起点, 分支上的commit将生成对应的新的commit并放在你指定的新的起点commit后, 分支上的老commit将被删除. rebase就是将你的分支从一个com ...
- git rebase 介绍
git rebase是对commit history的改写.当你要改写的commit history还没有被提交到远程repo的时候,也就是说,还没有与他人共享之前,commit history是你私 ...
- [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, ...
- 团队开发里频繁使用 git rebase 来保持树的整洁好吗?
用了以后, 树可以非常清晰, 某种程度上便于追踪, 但是 push --force 就多多了,不用呢, 合并没有远程仓库被修改的麻烦, 可是追踪又不清晰... git rebase是对commit h ...
- git merge和git rebase的区别(转)
Description git rebase 和 git merge 一样都是用于从一个分支获取并且合并到当前分支,但是他们采取不同的工作方式,以下面的一个工作场景说明其区别 场景: 如图所示: ...
- git squash 和 git rebase
In git, what is the difference between merge --squash and rebase? 上面链接的回答中的总结: Both git merge --squa ...
- git rebase vs git merge详解
https://medium.com/@porteneuve/getting-solid-at-git-rebase-vs-merge-4fa1a48c53aa#.std3ddz0g 请参考另外一篇文 ...
- git rebase 和 git merge 总结
git merge 和 git rebase 都是用于合并分支,但二者是存在区别的. 在使用时,记住以下两点: 当你从 remote 去 pull 的时候,永远使用 rebase(除了一个例外) 当你 ...
随机推荐
- ACM——圆柱体的表面积
lems 1092 圆柱体的表面积 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:2697 测试通过:414 ...
- XMLHttpRequest cannot load的问题解决方法
在chrome中可以用--allow-file-access-from-files 命令来解决这个问题.右键点击chrome的快捷方式选择属性.在目标一栏中添加--allow-file-acces ...
- IP-MAC绑定导致网络故障
前段时间将一台服务器A的服务迁移至了另外一台服务器B,外网IP地址也顺带迁移过来了,结果网络出现了问题. 其中内网是畅通的,但是外网IP怎么都连不上另外一台路由C(B和C是在一个交换机下的,网段也相同 ...
- ssh(Struts2+hibernate+spring)简单分页
实体类+实体映射+entity(pagebean)+dao层+service层+action层
- ACTIVEX 重新安装与卸载
1.卸载工具 SREngLdr.EXE,打开后执行 系统修复->浏览器加载项,找到对应的ACTIVEX,点击删除.OK 2.开发人员如遇到ACTIVEX版本更新.可在OBJECT 里加入更高版本 ...
- 常用JS正则表达式收集
1.去掉字符串前后空格,不会修改原有字符串,返回新串.str.replace(/(^\s*)|(\s*$)/g,'');
- switch case实现两个数的算术运算
方法一: package com.liaojianya.chapter1; import java.util.Scanner; public class SwitchDemo1 { public st ...
- avconv转换视频
提取指定stream time avconv -i i.mkv -map 0:0 -map 0:1 -map 0:5 -c:v copy -c:a:0 mp3 -c:s copy o.mkv 合并 a ...
- 『奇葩问题集锦』Ruby 切换淘宝源报错WARNING: Error fetching data: SSL_connect returned=1 errno=0 state=SSLv3 read s erver certificate B: certificate verify failed
===>首先需要使用https<===https://ruby.taobao.org/ 第一步 下载http://pan.baidu.com/s/1kU0rxtH 复制到ruby安装的根目 ...
- less学习-浏览器端编译(一)
demo地址 http://www.qq210.com/shoutu/android 1.下载less包,官网 2.引入less文件 <link rel="stylesheet/les ...