Why would git merge set my svn url to the branch
On my master checkout I can do a git svn info
and the url is svn://myrepo.com/trun
k
when on my new_feature checkout the svn url is svn://myrepo.com/branches/new_feature
.
After running a git merge new_feature
on my master checkout the master url is changed to svn://myrepo.com/branches/new_feature
. This makes both my master and new_feature pointing to the some place and I can no longer git svn dcommit
to trunk.
NOTE: This was working last week, and the only thing I can think of that could be different is that I needed to update the branch to trunk. I ran git merge trunk
on my branch. Perhaps it git will no longer let me merge my branch back to trunk no开发者_JAVA百科w?
I would like to know why this is and how to keep that from happening or fix it after it has happened.
git svn doesn't make a serious attempt at representing git merges in the svn data model (possibly because it can't be done properly). The svn branch information is picked up from git log messages; somehow the new_feature appeared first in the log. Following the first merge parent would have been better (edit: git-svn probably did, see below).
Anyway, the recommended way to handle this is not to record merges (using git merge --squash
instead), or to switch to git completely.
Seeing your edit: your merge back into trunk must have been a fast-forward. So git-svn followed the first parent of the first merge it saw, which was the merge of trunk into new_feature, until it found a log message with git-svn metadata. Prevent git from fast-forwarding merges into trunk by using git merge --no-ff feature_branch
.
per the git documentation:
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
...so when you merged your new-feature
branch (which had been dcommitted and has a git log with a git-svn-id
pointing to its branch) into your master
branch (which prior to the merge had a git-svn-id
log pointing to trunk) you gave master
a --first-parent
log with git-svn-id
pointing to the wrong branch new-feature
This is why there warnings all over the place to be careful when merging stuff backed by svn (or not to do it at all).
精彩评论