How does git-svn know which branch to dcommit to?
My repo is SVN, and I do all development with git. We have a standard layout, and I initialized my local repo with git svn init -s <url to repo>
Here's my workflow for working with branches:
# creates a new branch remotely
git svn branch new-branch-name
# switches to a branch or trunk locally
git reset --hard name-of-branch
git reset --hard trunk
# merge changes from trunk into a branch
git reset —hard name-of-branch
git merge trunk
git svn dcommit
That last command above will commit the changes to the branch name-of-branch. My question is, how does git know this? When I do git reset --hard foo
, what exactly happens?
This might just come down to a general question about git. Every time I try to research an answer I get confused about if svn integration is开发者_C百科 a special case or not.
git-svn
will look up the commit tree for ancestor commits that correspond to active SVN branches (the refs/remotes/...
branches that correspond to branches in SVN). It will then dcommit to those.
Note that you should not merge and then dcommit -- SVN's and Git's branching model do not match up, and this kind of thing can fubar your SVN history. You should instead git rebase trunk
when you are on the branch. (Alternatively, git svn rebase
.)
Also, be aware that the branch you check out prior to the rebase should be a local branch. If it is not, you can create one with git checkout -b local-branch-to-create remote-branch
. Then git rebase trunk
.
If you want to squash all of the commits that were rebased into one, then do this after the rebase: git reset --soft trunk && git commit
.
Once you are happy with the commits that now live on top of trunk, just git svn dcommit
to push them to the SVN server.
Isn't it as simple as creating a local branch and tracking a remote svn branch?
When you do a git svn init --stdlayout url-of-svn-repo
, git brings down the whole svn repo, compresses it so that it is operable with git.
After that it is just a matter of fact of doing something like:
git checkout -b mybranch -t remotes/mybranch
If you have a local branch tracking a remote branch, git svn dcommit
pushes only to the tracked remote branch.
Simple way if you'd like to dcommit git master into svn trunk, try the following commands:
git checkout master
git rebase trunk
git svn info # To verify that you're on the right branch
git svn dcommit
The same when on the other branch (e.g. 6.x)
git checkout 6.x
git rebase 6.x # or git rebase remotes/6.x
git svn info
git svn dcommit
精彩评论