在develop分支上rebase另外一个分支master,是将master作为本地,develop作为远端来处理的。

最后的效果是,develop分支看起来像是在master分支的最新的节点之后才进行开发的

develop分支上的commit记录

Administrator@LuJunTao MINGW64 /f/GitMerge/demo (develop)
$ git log
commit f529181aa7aa12794b261b5be57e948792168dd6  C5
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:43:21 2015 +0800

1.添加I love you

commit ccdaa5fd698d68854ad43bfc1ddef614ea2441ac  C4
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:43:02 2015 +0800

1.删除hello world

commit dc697947fccd64b310d5b910c6c8faca0a6a914d   C3
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:41:39 2015 +0800

1.添加world

commit 1f14a3c4a2bb5d9a26b6198733097f6801f6dcb9  C2
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:41:15 2015 +0800

1.添加hello

commit caf9736695f78779e9bae77afbc49d97a5e4959c    C1
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:40:48 2015 +0800

1.新增一个文件

master分支上的commit记录

Administrator@LuJunTao MINGW64 /f/GitMerge/demo (master)
$ git log
commit 618a561d8084af6b75ee6a9864bd2747c377eff6  C7
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:53:54 2015 +0800

添加lu

commit dc7ce42604209cc1cfb0b871043d89fd324830e3  C6
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:53:11 2015 +0800

添加chuck

commit dc697947fccd64b310d5b910c6c8faca0a6a914d  C3
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:41:39 2015 +0800

1.添加world

commit 1f14a3c4a2bb5d9a26b6198733097f6801f6dcb9  C2
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:41:15 2015 +0800

1.添加hello

commit caf9736695f78779e9bae77afbc49d97a5e4959c  C1
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:40:48 2015 +0800

1.新增一个文件

develop分支和master分支的共同的父节点

commit dc697947fccd64b310d5b910c6c8faca0a6a914d
Author: ChuckLu <244657538@qq.com>
Date: Tue Aug 11 14:41:39 2015 +0800

1.添加world

C1<--C2<--C3<--C6<--C7      master分支

<--C4<--C5      develop分支

rebase开始

1.首先切换到develop分支

git checkout develop

2.在develop分支上进行rebase

git rebase master

【rebase是在master分支的最后一个提交C7上开始的】

将C4和C7合并,得到一个合并结果result1

再将C5和result1合并,得到一个合并结果result2

C4和C7合并的时候产生冲突,Local是C7,C5作为Remote出现。

在develop分支上rebase另外一个分支master,是将master作为本地,develop作为远端来处理的。

处理完冲突之后,保存,并标记为解决冲突

1.第一种处理方式,处理结果为直接使用右侧的文件

git rebase --continue

这时候,会收到提示,

Administrator@LuJunTao MINGW64 /f/GitMerge/demo (develop|REBASE 1/2)
$ git rebase --continue
Applying: 1.删除hello world
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

即便是已经处理了冲突,但是这个冲突比较特殊。上图的合并结果,是以右侧的现有文件(Local)作为处理结果的。

关于这个,这里有解释http://stackoverflow.com/questions/4033009/git-rebase-conflicts-keep-blocking-progress

Word of caution: Please note that git rebase --skip will completely drop the commit that git tried to rebase.

In our case, this should be okay since git is complaining this is an empty commit.

If you think you've lost changes once the rebase is complete, you can use git reflog to get the commit id of your repository before the rebase,

and use git reset --hard to get your depot back in that state (this is another destructive operation).

这个时候,需要通过git rebase --skip来跳过

2.第二种处理方式,合并结果,既不是Local也不是Remote的

这种情况下git rebase --continue

就可以正常工作

当前处于分支A,执行命令

git rebase B

那么在处理冲突的时候,Local是B,Remote是A

C1  v0.10.12     5fc35f2b069116b334a20f324bf135237627e404

C2  load language setting before GameV2 initialized    78f9d8de291f0e241bcb0ecd7ce532109fcef657

C3  fix config not loading early enough,causing no language besides enUS to work  0bb37cb02d9a120e6e311303bffd85d2c5d648bb

C4  v0.10.13 (language fix)   3b82bb138f149788611f48c8fdfbf1f18ea3b029

1.在chucklu_master的分支上执行git rebase temp

以temp的最后一个提交对象v0.10.13,假定这次提交为C4,

chucklu_master上,实际只有一个新的提交,假定为C2

rebase的时候,会把C2的修改和C4进行一次合并,发现有冲突

手动合并,

git rebase --continue

如果合并的结果是Local的话[会提示git add],这种情况下,直接就git rebase --skip

上面这句话,以为着,合并结果是temp的节点C4,这会导致,chucklu_master上的提交记录直接被忽略掉

Administrator@LuJunTao MINGW64 /d/SourceCode/GameSourceCode/Hearthstone-Deck-Tracker (chucklu_master|REBASE 1/1)
$ git rebase --continue
Applying: load language setting before GameV2 initialized
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

如果收到这样的提示,则说明这次的合并,是无效的。当前分支上的这一次commit,对于基底分支temp来说,没有任何意义。所以直接跳过。

2.在temp分支上执行 git rebase chucklu_master

以chucklu_master的最后一个提交对象,假定这次提交为C2

temp分支,实际上有2个提交,假定为C3和C4

rebase的时候,首先是C3和C2进行合并,得到结果result

然后把C4和上一步的result合并,得到另外一个结果result1

生成了新的commit  fix config not loading early enough, causing no language besides enUS to work.   dd076d7b5da66c17eae4bbdc8a7af4c635ef0360

虽然提交信息是一样的,但是SHA的值已经改变

v0.10.13 (language fix)     238a2d1042106c8e94722794d980e75439261be5

===2015年10月20日更新===

$ git rebase --continue
ZBMYun/SourceCode/ZITakerHS/ZITaker/UI/FormDeviceInfo.cs: needs update
You must edit all merge conflicts and then
mark them as resolved using git add

处理完冲突之后,提示这个。记得用tortoisegit的图形化界面处理完冲突的,并且标记了resolved量。

不知道为什么还提示这个,

按照提示执行

$ git add UI/FormDeviceInfo.cs

最后再执行git rebase --continue就完成了

===2015年10月25日凌晨3:41更新===

$ git rebase --continue
Applying: Re-Fix gold progress display, add background image
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

这种情况下,没有提示有具体的文件需要git add

直接执行git rebase --skip就可以了

执行完成以后,需要记得和之前第三方的最后一次提交,进行compare。如果一致的话,就说明rebase是有效的

git rebase实战的更多相关文章

  1. Git rebase命令实战

    一.前言 一句话,git rebase 可以帮助项目中的提交历史干净整洁!!! 二.避免合并出现分叉现象 git merge操作 1.新建一个 develop 分支   2.在develop分支上新建 ...

  2. git rebase 的使用

    rebase 在 Git 中整合来自不同分支的修改主要有两种方法:merge 以及 rebase. 在本节中我们将学习什么是“rebase”,怎样使用“rebase”,并将展示该操作的惊艳之处,以及指 ...

  3. Git rebase的使用

    rebase 在 Git 中整合来自不同分支的修改主要有两种方法:merge 以及 rebase. 在本节中我们将学习什么是“rebase”,怎样使用“rebase”,并将展示该操作的惊艳之处,以及指 ...

  4. Git应用详解第九讲:Git cherry-pick与Git rebase

    前言 前情提要:Git应用详解第八讲:Git标签.别名与Git gc 这一节主要介绍git cherry-pick与git rebase的原理及使用. 一.Git cherry-pick Git ch ...

  5. git rebase

    git rebase -i HEAD~[number_of_commits] git rebase -i HEAD~2

  6. git rebase与 git合并(error: failed to push some refs to)解决方法

    1.遇到的问题 本地有一个git仓库,在github上新建了一个空的仓库,但是更新了REWADME.md的信息,即在github上多了一个提交. 关联远程仓库,操作顺序如下: git remote a ...

  7. 聊下 git rebase -i

    在使用git作为源代码管理工具的时候,开发的时经常会面临一个常见的问题,多个commit 需要合并为一个完整的commit提交. 在一个基本的迭代周期里,你会有很多次commit,有跟配置文件相关的, ...

  8. [git]rebase和merge

    转自:http://blog.csdn.net/wh_19910525/article/details/7554489 Git merge是用来合并两个分支的. git merge b # 将b分支合 ...

  9. git merge 和 git rebase 小结

    Git merge是用来合并两个分支的. git merge b # 将b分支合并到当前分支 同样 git rebase b,也是把 b分支合并到当前分支 ---------------------- ...

随机推荐

  1. Log4Net 在多层项目中的使用小记

    原文地址:http://www.cnblogs.com/zdh8675/p/3645556.html 这几天刚好在调整一个项目,把一些自己不是很清楚的东西先试验一下,这篇文章主要是对我在项目中需要使用 ...

  2. 如何创建windows xp 虚拟机

         如何创建windows xp 虚拟机 一.所需软件 1. VMware-workstation-full-12.0.0-2985596 赠送vm12 激活key一枚: 5A02H-AU243 ...

  3. sql server varchar和nvarchar的区别

    一.前言 在了解varchar 和nvarchar之前咱们先了解一下这些词的字面和常用意思,以方便我们更好的使用: SQL SERVER中生成的语句中,字符串前加N.N 前缀必须是大写字母.是Unic ...

  4. 注释玩转webapi

    using System; using System.Collections.Generic; using System.Net.Http.Formatting; using System.Web.H ...

  5. Cocos2d-x 3.0 cocostudio骨骼动画的动态换肤

    概述 游戏中人物的状态会发生改变,而这种改变通常要通过局部的变化来表现出来.比如获得一件装备后人物形象的改变,或者战斗中武器.防具的损坏等.这些变化的实现就要通过动态换肤来实现.在接下来的这个Demo ...

  6. JVM - 内存溢出问题排查相关命令jcmd jmap

    jcmd http://docs.oracle.com/javase/8/docs/technotes/tools/windows/jcmd.html jcmd-l  列出正在执行的JAVA进程ID ...

  7. 分享一下个人的Vim配置文件

    强烈拥护开源精神,高举开源大旗,今天我就分享下我自己结合网上还有自己实际使用配的vimrc,可以给各位参考下,不要见笑哈,具体说明我在rc里写的也很详细,可以具体看下,也希望可以借这个机会能多认识认识 ...

  8. Linux 内核学习的经典书籍及途径

    from:http://www.zhihu.com/question/19606660 知乎 Linux 内核学习的经典书籍及途径?修改 修改 写补充说明 举报   添加评论 分享 • 邀请回答   ...

  9. rownum

    rownum是一个伪列,oracle数据库会对查找到的数据 从1 开始递增指定每行的rownum值, 当查询条件里有 rownum时(比如 where rownum>2),数据库会依次从数据集里 ...

  10. sql的连接查询方式

    1 SQL join 用于根据两个或多个表中的列之间的关系,从这些表中查询数据. Join 和 Key 有时为了得到完整的结果,我们需要从两个或更多的表中获取结果.我们就需要执行 join. 数据库中 ...