zoukankan      html  css  js  c++  java
  • 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.

    冲突的处理可以去原文看

  • 相关阅读:
    fetch数据请求
    React exact路由精确匹配
    React Router中的Link和NavLink组件有什么区别?
    new FileReader() 文件上传
    git stash部分文件
    主机屋的免费云虚拟主机
    MySQL数据库默认的存储引擎类型是MyISAM并不支持事务的坑,要把存储类型改为InnoDB
    使用ExcelPackage,OfficeOpenXml做EXCEL导入时一个方法的坑,对应类的字段只能定义为string类型
    mysql两个关联表,同名字段同时返回时,原字段名写靠前的表的字段名会可以保留原字段名,靠后的会被自动as为(1)这样的,
    MySql 里的IFNULL、NULLIF和ISNULL用法-区别于MSSQL
  • 原文地址:https://www.cnblogs.com/chucklu/p/4747833.html
Copyright © 2011-2022 走看看