我发现了类似的问题,如一个下面:如何拆分主分支?
这个问题已经有了答案在这里:
另外,我发现精彩的YouTube视频how to split commit。
但是,其他sof问题或youtube没有完全解释为了拆分根提交需要做什么。
让我描述我所: 让的说我有两次提交 “master” 分支:
- 根: “初始化” ce0418e
- “Commit01” 8585a44
我有另一个分支“anotherBranch”,有三个提交:
- root:“init”ce0418e
- “testCommit01” 459ca66
- “testCommit02” f9f0ba4
所以我想分裂承诺 “初始化”(它包含文件:的.gitignore; README.md; myClass)
我需要该文件.gitignore和README.md成为新“init”(新根)的一部分,myClass成为另一个提交消息“myClass Splitted”并成为主分支的一部分。
从我找出我应该做的下一步骤其他SOF问题:
$git rebase -i --root
中出现了新的窗口,并改变从“捡”到ce0418e前面的“编辑” “初始化” ESC然后再移位+ ':' + 'WQ'
现在我收到消息:
停在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
进行拆分,但它似乎不适用于根提交。
所以我的问题是我下一步该怎么做?
thx为您的回应。 “当在ce0418e .. init中停止时,删除工作目录中的myClass”1)请告诉我如何删除工作目录中的myClass? 2)根据你的方案,我是否正确地理解我不能拆分根,以便主分支看起来像这样:A' - E --- B'主?许多thx响应。 –
对于您的问题:1.只需在您的本地回购,找到myClass并删除它。是的,你可以按不同的顺序制作:A'-E-B。在交互式窗口中,您只需调整oder:'edit ce0418e','选择E'和编辑8585a44'。 'git rebase -i'是一个强大的命令,您可以编辑,重新排序或删除它的提交。 –