git-svn commits to wrong branch / how to merge svn branch via git-svn

試著忘記壹切 提交于 2019-12-24 09:27:28

问题


I have a SVN repository which I checked out with git-svn, using the --stdlayout option (at that time, the repo was empty).

I then worked on the master branch for a while. When using git svn dcommit, it would svn-commit my changes to https://my.host/repo/trunk like it should.

At some point I created a branch named "arithmetics" with git. Later I wanted to create that branch in svn too, so I did a git svn branch arithmetics and then a git branch --set-upstream arithmetics remotes/arithmetics as suggested by a website. I suppose this is where things went wrong, as I got a warning about --set-upstream being deprecated.

When calling git svn dcommit, it would commit to https://my.host/repo/branches/arithmetics, so far so good. But then I noticed, that dcommit would commit to that branch regardless of the currently checked out branch in the git repository, when I tried merging the branch back into master.

I even tried creating a new clone from svn, merging the branch into master there. I also tried checking out trunk explicitly with git checkout -b local/trunk remotes/trunk, then merging the branch into that and then git svn dcommit. It would always commit to the branch again.

How can I fix this?

PS: I used git rebase for merging, as I read, that merge-commits were problematic with git-svn, so I don't have any of those.


回答1:


You cannot dcommit git branches to an SVN repository, because Git and SVN have totally different notions of branches. Merging with git and then calling dcommit will linearize your history (quite the same as with rebase) and then push to the currently checked out branch.

Here's the important part from the manpage of git svn:

MERGE TRACKING
While git svn can track copy history (including branches and tags) for repositories adopting a standard layout, it cannot yet represent merge history that happened inside git back upstream to SVN users. Therefore it is advised that users keep history as linear as possible inside git to ease compatibility with SVN (see the CAVEATS section below).

Also, the caveats section has a paragraph dedicated to your problem:

Running git merge or git pull is NOT recommended on a branch you plan to dcommit from because Subversion users cannot see any merges you’ve made. Furthermore, if you merge or pull from a git branch that is a mirror of an SVN branch, dcommit may commit to the wrong branch.

If you do merge, note the following rule: git svn dcommit will attempt to commit on top of the SVN commit named in

git log --grep=^git-svn-id: --first-parent -1


来源:https://stackoverflow.com/questions/14172446/git-svn-commits-to-wrong-branch-how-to-merge-svn-branch-via-git-svn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!