简体   繁体   English

将正在进行的工作从Git分支移至主题分支

[英]Moving in-flight work from Git branch and move it to a topic branch

Background 背景

If I were to have a git branch that looks like this: 如果我要拥有一个如下所示的git分支:

-- A -- B -- C -- D -- E --

The commits closer to present time might not have the change the files in the earlier commits. 与当前时间更近的提交可能没有更改早期提交中的文件。

I would want my repository to look like this after cleaning it up. 我希望我的存储库在清理后看起来像这样。

-- A -- B -- D -- E -- \\-- C --

Basically, I am migrating from one SCM tool (AccuRev) to git. 基本上,我正在从一种SCM工具(AccuRev)迁移到git。 We have four streams that represent environments. 我们有四个代表环境的流。 Each stream is inherited. 每个流都是继承的。 Prod > pre-prod > QC > Dev There could be change packages in QC that are not in Prod and so on. Prod > pre-prod > QC > Dev可能存在QC中不在Prod中的变更包,依此类推。 We can only migrate one stream over due to how history works in AccuRev, so we will migrate over the dev stream as the history is more granular. 由于历史记录在AccuRev中的工作方式,我们只能迁移一个流,因此随着历史记录的细化,我们将在开发流上迁移。 Therefore we will have the AccuRev dev stream mapped as the master branch in Git (and where the production builds will originate from so it needs to be stable). 因此,我们将把AccuRev dev流映射为Git中的主分支(以及生产构建的来源,因此它必须稳定)。


QUESTION: 题:

I'm looking for the best way to remove the in-flight work from the git master branch and move it to a topic branch. 我正在寻找从git master分支中删除进行中的工作并将其移至主题分支的最佳方法。

Bear in mind that one commit contains main changes after the migration is completed. 请记住,一次迁移包含迁移完成后的主要更改。

To move commit C from master branch to topic branch, you can use below commands: 要将提交Cmaster分支移动到topic分支,可以使用以下命令:

git checkout topic
git cherry-pick <commit id for C>
git checkout master
git rebase -i master~4

~4 stands for how many commits you want to rebase from the HEAD ~4代表您要从HEAD重新设置多少个提交

In the interactive window, change commit C as drop : 在交互式窗口中,将commit C更改为drop

pick B
drop C
pick D
pick E

Now commit C is moved from master to topic branch. 现在,提交Cmaster移到topic分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM