2016-12-27 85 views
-1

我发现了类似的问题,如一个下面:如何拆分主分支?

这个问题已经有了答案在这里:

Change first commit of project with Git? [duplicate]

Edit the root commit in Git?

另外,我发现精彩的YouTube视频how to split commit

但是,其他sof问题或youtube没有完全解释为了拆分根提交需要做什么。

让我描述我所: 让的说我有两次提交 “master” 分支:

  1. 根: “初始化” ce0418e
  2. “Commit01” 8585a44

我有另一个分支“anotherBranch”,有三个提交:

  1. root:“init”ce0418e
  2. “testCommit01” 459ca66
  3. “testCommit02” f9f0ba4

所以我想分裂承诺 “初始化”(它包含文件:的.gitignore; README.md; myClass)

我需要该文件.gitignore和README.md成为新“init”(新根)的一部分,myClass成为另一个提交消息“myClass Splitted”并成为主分支的一部分。

从我找出我应该做的下一步骤其他SOF问题:

  1. $git rebase -i --root

  2. 中出现了新的窗口,并改变从“捡”到ce0418e前面的“编辑” “初始化” ESC然后再移位+ ':' + 'WQ'

  3. 现在我收到消息:

停在ce0418e ..初始化

你可以修改现在提交,与

git commit --amend 

一旦你满意你的变化,运行

git rebase --continue 
  • 所以我做$git commit --amend 我收到的窗口指出:
  • 初始化

    Please enter the commit message for your changes. Lines starting 
    with '#' will be ignored, and an empty message aborts the commit. 
    
    Date:  Tue Dec 26 18:01:07 2016 +0100 
    
    interactive rebase in progress; onto 11448c4 
    Last command done (1 command done): 
        edit ce0418e init 
    Next commands to do (2 remaining commands): 
        pick 8585a44 Commit01 
    You are currently editing a commit while rebasing branch 'master' on '11448c4'. 
    
    
    Initial commit 
    
    Changes to be committed: 
         new file: .gitignore 
         new file: README.md 
         new file: myClass 
    

    再次不久,我需要单独的文件:的.gitignore和README.md从文件:MyClass的 怎么会呢?

    显然,我需要在这个新窗口中进行一些更改,但是更改了哪些内容? 我试图通过$git status进行拆分,但它似乎不适用于根提交。

    所以我的问题是我下一步该怎么做?

    回答

    0

    所以你当前的git的日志结构,如:

    A---B  master 
    \ 
        C---D anotherBranch 
    

    一种 “初始化” ce0418e

    B中 “Commit01” 8585a44

    下 “testCommit01” 459ca66

    D代表“testCommit02”f9f0ba4

    而现在要将其更改为:

    A’---B’---E master 
    \ 
        C’---D’ anotherBranch 
    

    A 'B',C '和d' 只包含的.gitignore和READMA.md(删除 MyClass的),并添加了新的承诺主分支包含myClass文件。

    所以你可以做如下:

    1. 添加主分支通过git checkout mastergit commit -am 'myClass Splitted'
    2. 重写主分支(A和B图)由git rebase -i --root一个新的提交。

    在交互式窗口,改变A和B作为编辑,edit ce0418eedit 8585a44pick E

    stopped at ce0418e.. init在工作目录删除MyClass的,和输入git add myClassgit rebase --continue

    对于8585a44 (master|REBASE-i 2/3),也删除MyClass的,然后输入git add myClassgit rebase --continue

  • git checkout anotherBranchgit rebase -i --root重写另一个分支。
  • 在交互式窗口中,更改C和D进行编辑,edit 459ca66edit f9f0ba4

    然后删除myClass,并做与主分支相同的事情。

    +0

    thx为您的回应。 “当在ce0418e .. init中停止时,删除工作目录中的myClass”1)请告诉我如何删除工作目录中的myClass? 2)根据你的方案,我是否正确地理解我不能拆分根,以便主分支看起来像这样:A' - E --- B'主?许多thx响应。 –

    +0

    对于您的问题:1.只需在您的本地回购,找到myClass并删除它。是的,你可以按不同的顺序制作:A'-E-B。在交互式窗口中,您只需调整oder:'edit ce0418e','选择E'和编辑8585a44'。 'git rebase -i'是一个强大的命令,您可以编辑,重新排序或删除它的提交。 –

    相关问题