简体   繁体   中英

git branches for SVN and Github

Here is a simple path of what I'm doing:

$ cd /newdir
$ git clone git@github.com:... .
$ git branch -m master github
$ git svn clone svn+ssh://... .
$ git branch -m master SVN

Then I have some scripts that do what is needed before pushing to Github.

I need the SVN and github branches because the files on both branches are the same but with different content. Before pushing files to Github I add some header. The two branches are also used to allow not all files on SVN go to Github.

All updates are from SVN branch to github branch. Occasionally I would add something on github branch that is not on SVN. I'll never send files/updates from github branch to SVN branch.

My problem 1 is that every time I do git svn fetch, a new master branch is created. How can I tell git svn fetch to use SVN local branch instead of master local branch?

After every:

$ git svn fetch

I could:

$ git checkout SVN
$ git merge master
$ git branch -d master

But does not look as a smart way of doing it.

Then I have a problem telling my local git that the local github branch is the remote/master branch at Github. The command

$ git push git@github.com:...

That worked perfectly before renaming local branches, now is not doing what I want.

So my 2 questions:

1 - Telling git svn to always use local SVN branch when getting updates from SVN server
2 - Telling git that local github branch is remote master branch at github

You can not use merge with SVN based branches (read the git svn manual; it very carefully states this in multiple places). If you need to merge, do it the other way where the SVN tree is merged into other branches (but never never merge something else into the SVN tree).

Let git svn have the master branch and if you need to do development in a separate branch, use another one for yourself (say master2 ). Then when you want the work in it commited to the master branch, do:

git checkout master2
git rebase master
git checkout master
git merge --ff-only master

And when you add the github master repo, do it in a separate branch:

git checkout master
git checkout -b githubmaster
git remote add github .....
git pull github master

And simply always do the above to pull into the github specific branch. But you'll likely run into issues with the github server when you need to push back into the github stream after doing rebases and thus will need to be mean and use push -f to force update the github tree after a diverge.

And ok, technically, I lied about not being able to merge into the SVN tree. But really, you'll save a lot of headaches if you don't. The reality is that git svn isn't meant to be a fully integrated git system. It's really just a "better SVN client" than SVN itself. You really can't use git svn and expect to get the full power of git itself. Sad, but unfortunately true. I know because I've been down your path already and am doing what you want to do. The upshot is that you really can't do merging and have it all play nicely together. SVN just can't handle it.

首先通过git clone git@git.corp.xyz.com:corp克隆gitHub,然后进行git checkout(分支的名称),然后是git branch(将显示分支的名称)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM