I'm trying to import a CVS repository into git. Unfortunately, we've been using a really old method of creating releases from our CVS repo, that doesn't involve any actual CVS branches or tags, but keep that information in a separate system. Consequently, almost all of the development happens on the CVS trunk. So, one file may be added very early in the history, but doesn't become part of the release for 6 months.
What I'd like to do is import this CVS repo into git, and use rebasing to move these commits to development branches. I do have some branches from CVS though, so I really want to move all branches.
Say I've got this:
F---G---H topic
/
A---B---C---D---E---I---J master
B
is the commit that I want to move to its own branch. I want the result to look like this:
F`---G`---H` topic
/
A---C`---D`---E`---I`---J` master
\
B some_unfinished_feature
But rebasing only master
results in:
git checkout -b some_unfinished_feature B
git rebase --onto A B master
A---C`---D`---E`---I`---J` master
\
\ F---G---H topic
\ /
B---C---D---E
\-some_unfinished_feature
Can I get git to rebase topic
onto E'
in one rebase command? I could potentially have lots of branches that I want to move onto their corresponding new commit. Or is there a way that I can get a mapping between E
and E'
?
F---G---H topic
/
A---B---C---D---E---I---J master
git checkout B
git branch BRANCH-B
git checkout master
git rebase -i HEAD~6
(remove commit B)
git rebase --onto D' D topic
This should do it assuming no conflict ;)
In your question you want to move starting from C
commit. B
is left as branch based on A
.
First we should give name to it:
git branch -b some_unfinished_feature <B-ish>
This command will create some_unfinished_feature
branch starting from <B-ish>
commit.
The <C-ish>
is upstream. You can view all commits that would be rebased:
git log <C-ish>..topic
You can notice that I
and J
will not be rebased because those are different branch. You should rebase it separately later.
Now rebase your topic
onto <A-ish>
starting from <C-ish>
:
git rebase -p --onto <A-ish> <C-ish> topic
-p
flag will preserve any merges which occur from <C-ish>
to topic
When this command complete you will get:
some_unfinished_feature
/
A---B---C---D---E---I---J master
\
C`---D`---E`
\
F`---G`---H` topic
Now you should rebase master
onto <E-ish>
from <I-ish>
git rebase -p --onto <E-ish> <I-ish> master
Voila:
A---B some_unfinished_feature
\
C`---D`---E`--I`---J` master
\
F`---G`---H` topic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With