简体   繁体   中英

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:

-- 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. 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. 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. 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).


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.

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:

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

In the interactive window, change commit C as drop :

pick B
drop C
pick D
pick E

Now commit C is moved from master to topic branch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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