简体   繁体   English

SVN和Github的git分支

[英]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. 然后,我有一些脚本可以执行推送到Github之前所需的操作。

I need the SVN and github branches because the files on both branches are the same but with different content. 我需要SVN和github分支,因为两个分支上的文件相同,但内容不同。 Before pushing files to Github I add some header. 在将文件推送到Github之前,我添加了一些标题。 The two branches are also used to allow not all files on SVN go to Github. 这两个分支还用于允许并非SVN上的所有文件都转到Github。

All updates are from SVN branch to github branch. 所有更新都是从SVN分支到github分支。 Occasionally I would add something on github branch that is not on SVN. 有时我会在github分支上添加不在SVN上的内容。 I'll never send files/updates from github branch to SVN branch. 我永远不会将文件/更新从github分支发送到SVN分支。

My problem 1 is that every time I do git svn fetch, a new master branch is created. 我的问题1是每次执行git svn fetch时,都会创建一个新的master分支。 How can I tell git svn fetch to use SVN local branch instead of master local branch? 如何告诉git svn fetch使用SVN本地分支而不是master本地分支?

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. 然后我有一个问题告诉本地git本地github分支是Github上的remote / master分支。 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). 不能将合并与基于SVN的分支一起使用(请阅读git svn手册;它在多个位置都非常谨慎地指出了这一点)。 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). 如果您需要合并,请以另一种方式将SVN树合并到其他分支中(但永远不要将其他内容合并到SVN树中)。

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 ). git svn具有master分支,如果您需要在单独的分支中进行开发,请自己使用另一个(例如master2 )。 Then when you want the work in it commited to the master branch, do: 然后,当您要将其中的工作提交到master分支时,请执行以下操作:

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: 当您添加github主仓库时,请在单独的分支中进行操作:

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. 并且只需始终执行上述操作即可进入github特定分支。 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. 但是,当您需要在进行重新设置后推回github流时,可能会遇到github服务器问题,因此将变得卑鄙并使用push -f在分歧之后强制更新github树。

And ok, technically, I lied about not being able to merge into the SVN tree. 好的,从技术上讲,我撒谎说无法合并到SVN树中。 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. 现实情况是git svn并不意味着是一个完全集成的git系统。 It's really just a "better SVN client" than SVN itself. 实际上,它只是比SVN本身“更好的SVN客户端”。 You really can't use git svn and expect to get the full power of git itself. 您确实不能使用git svn并期望获得git本身的全部功能。 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. SVN不能处理它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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