I usually using git for versioning, but right now I am stuck with sources in a svn repository, so I am using git-svn to access that repository. However this seems to lead to some trouble, when I try to use local branches.
I usually only commit my local repositories about once a day, so I might have commits in my local master, that I have not yet send upstream. When I create a branch at this point, and then someone else commits to the upstream repository, all commits between the current one and the last one that was synced upstream get duplicated.
To make this clearer here a short picture:
A-B-C-D-E
\
\-F
The upstream repository is at A and the two branches are at E and F respectively. Doing a git svn rebase leads to:
A-G-H-B-C-D-E
\
\-B-C-F
Where G and H are the commits that were taken from the upstream repo. I already tried to get the two commits to the other branch as well by switching there and doing another git svn rebase. But this leaves me there:
A-G-H-B-C-D-E
\
\-G-H-B-C-F
So this leads to even more duplication of commits. Is there a clean way to handle this situation?
You can use git rebase
to reapply any range of commits onto any particular commit, which sounds like what you want here. This technique works for moving any range of commits, but as I mention at the bottom, if you really only have a single commit F
on your branch, then it's easier to just cherry-pick. However, first I'll describe how you would do it with git rebase
, since that's more generally useful.
(n.b. I'm going to rename your commits slightly since the two B
s, C
s, etc. will have different commit IDs after rebasing.)
git svn rebase
So, if you were wanting to do this rebasing after the first git svn rebase
you would be in the situation:
A-G-H-B'-C'-D'-E'
\
\-B-C-F
At this point, you could have done:
git rebase --onto C' C F
... which would have created:
A-G-H-B'-C'-D'-E'
\ \
\-B-C-F \-F'''
git svn rebase
If the situation is as you describe after the second git svn rebase
, that would look like this:
A-G-H-B'-C'-D'-E'
\
\-G'-H'-B''-C''-F''
In that case you could similarly do:
git rebase --onto C' C'' F''
To create the graph:
A-G-H-B'-C'-D'-E'
\ \
\ \- F'''
\
\-G'-H'-B''-C''-F''
... and you can just forget about G'
through to F''
.
However, in both of these cases, you're only moving a single commit, so it's probably easier to cherry-pick the commit. In other words, you could do:
git checkout -b new-experiment C'
git cherry-pick F
I hope that's of some use.
You should always use 'git svn rebase' before 'git svn dcommit' to avoid such problems. This mirrors common svn usage of updating before commit. See section "REBASE VS. PULL/MERGE" in http://git-scm.com/docs/git-svn for details.
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