【问题标题】:How can I change what branch is my current branch based off?如何更改当前分支基于哪个分支?
【发布时间】:2011-11-24 11:36:34
【问题描述】:

情况是这样,我有三个分支,masterfix#1fix#2,后两个分支都在修复一个特定的错误。

问题是,我基于 fix#1fix#2,而不是从 master 分支,所以它看起来像这样

fix#2
|
fix#1
|
master

而不是

fix#1  fix#2
|     / 
master 

有什么简单的方法可以从fix#2 分支中删除所有fix#1 提交(实际上是一个提交)?

【问题讨论】:

    标签: git branch git-branch


    【解决方案1】:
    git rebase --onto master fix1 fix2
    

    但请确保您在执行此操作之前了解会发生什么以及所有后果。

    git rebase -h 输出:

    Usage: git rebase [--interactive | -i] [-v] [--force-rebase | -f] [--no-ff] [--onto <newbase>] (<upstream>|--root) [<branch>] [--quiet | -q]
    
    git-rebase replaces <branch> with a new branch of the
    same name.  When the --onto option is provided the new branch starts
    out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
    It then attempts to create a new commit for each commit from the original
    <branch> that does not exist in the <upstream> branch.
    
    It is possible that a merge failure will prevent this process from being
    completely automatic.  You will have to resolve any such merge failure
    and run git rebase --continue.  Another option is to bypass the commit
    that caused the merge failure with git rebase --skip.  To restore the
    original <branch> and remove the .git/rebase-apply working files, use the
    command git rebase --abort instead.
    
    Note that if <branch> is not specified on the command line, the
    currently checked out branch is used.
    
    Example:       git-rebase master~1 topic
    
            A---B---C topic                   A'--B'--C' topic
           /                   -->           /
      D---E---F---G master          D---E---F---G master
    

    【讨论】:

    • 我从未停止对 Git 文档的神秘性感到沮丧。
    • @MikeK,我不会说它特别神秘。但是一些与图形相关的图形概念很难用语言来解释。
    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 2018-03-24
    • 2018-05-05
    • 1970-01-01
    • 2020-01-09
    • 2013-12-09
    • 1970-01-01
    • 2013-11-04
    相关资源
    最近更新 更多