开发者

Syncing existing git with existing SVN repository

Okay, I made a mess. I have a SVN repository with my code and I have a local git repository in which I usually work, branch, etc.. I used to commit things from time to time from git into SVN using git-svn. Now I got a new computer and cloned my git repository from one to the other. I tried to use git-svn afterwards, but due开发者_开发百科 to a new version and me being not careful enough the configuration was somehow lost. So I used git svn init and clone to get back my history in SVN, but now the situation looks like this:

o--Z--o--....--X--o--o....--o  (master)
   |
   o--o--o--....--X (remotes/git-svn)

X is marking a state in which both repositories are in the same state (as master and git-svn where in sync on my old machine). Now, I'd like to commit everything from X to HEAD from master into my SVN repository, but when I use git svn dcommit -n it shows diffs way back to Z. How can I sync git-svn and git and svn again (so that I can use simply dcommit to commit stuff again)?

Is it possible to go back to X and use git svn set-tree X (because the current SVN holds exactly that version) and than go back to HEAD to do the git svn dcommit? I don't want to (blindly) try stuff on the SVN, as there is a lot of more stuff in it (by many other people) which I don't want to screw up.


git svn dcommit looks back in the history of your branch until it finds a commit message that contains a git-svn-id: line, so it'll go back to Z in your case, as you observe. I would try to rebase your master branch onto remotes/git-svn. I haven't tested this, but the following would be what I would try:

 # Make sure that you're on master
 git checkout master

 # Create a new branch here to save the old branch
 git branch old-master

 # Rebase everything after the X on master up to the tip of master
 # onto remotes/git-svn
 git rebase --onto remotes/git-svn <commit-ID-of-X-in-master> master

After that, your history should look like:

o--Z--o--....--X--o--o....--o  (old-master)
   |
   o--o--o--....--X (remotes/git-svn) --o--o....-o (master)

... and git svn dcommit should work as expected - however, I'd try it with --dry-run first, just to be sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜