Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git SVN and merging branches

Tags:

git

svn

git-svn

I am working on a svn project with two branches, lets call them

trunk
branches/foo

My idea is to clone the whole svn repository (telling git which folder are trunk, tags and branches), do the merge in git and then copy my merge to a svn working copy and commit the changes from svn.

In this workflow, will I be able to use gits merging power or will that only work for branches created with git itself?

like image 240
unkownt Avatar asked Nov 27 '10 09:11

unkownt


People also ask

Can you use git and SVN together?

git works perfectly fine with a svn repository on the other side, why not benefit from that? Certainly possible, and a fair move towards your colleagues, not to push unfinished changes. however there is one huge danger hidden in there: you will tend to make very few commits to the companies repository.

Can we merge two branches in git?

Git merge will combine multiple sequences of commits into one unified history. In the most frequent use cases, git merge is used to combine two branches.

Does SVN merge delete the branch?

If you merge a branch into trunk using "svn merge --reintegrate", you are recommended to delete the branch. If you want to do further development in that branch, you should "re-branch", effectively create a new branch with the same name, but rooted at the same revision as you merged the branch into trunk.


1 Answers

Create alias for checkout command:

git config alias.co checkout

Make sure that you local branches are up to date:

git co master    # checkout branch that tracks subversion's trunk
git svn rebase 
git co local/foo # checkout branch that tracks subversion's branches/foo
                 # It assumes that  the branch is created with the command:
                 # `git co -b local/foo remotes/foo`
                 # And the repo was created with:
                 # `git svn clone --stdlayout SVN_REPO_URL`
git svn rebase 

Merge branches:

# create new local branch based on `master`
git co master
git co -b merging_branch_foo 
# merge, resolve conflicts, etc (pure git)
git merge local/foo  

# rebase `merging_branch_foo` to linearize history for subversion
git rebase master # or `rebase -i`

# merge `merging_branch_foo` into `master`
git co master
git merge merging_branch_foo # --squash to create single commit

# commit changes to svn
git svn dcommit

# (optionally) delete `merging_branch_foo`
git branch -D merging_branch_foo
like image 66
jfs Avatar answered Sep 22 '22 06:09

jfs