简体   繁体   English

通过从原始svn仓库中获取所有svn部分来克隆git-svn仓库

[英]Clone a git-svn repo by getting all of the svn part from the original svn repo

How can I clone a git repo from my laptop (at home) to a server (at university) while getting most of the repo from a third (svn) repo at another uni that is the main codebase. 我如何将git存储库从我的笔记本电脑(在家)克隆到服务器(大学),同时从第三(svn)存储库的另一个uni(主要代码库)中获取大部分存储库。 I'd like to minimise the amount of home<->uni traffic by maximising uniOne<->uniTwo traffic. 我想通过最大化uniOne <-> uniTwo流量来减少home <-> uni流量。

this is what I have now on Laptop: 这就是我现在在笔记本电脑上所拥有的:

--o--o--o---o---o---o git-svn trunk  
         `--o--o-o--o git mybranch  

this is what I would like to get on uniOne: 这就是我想要上uniOne的方法:

--o--o--o---o---o---o git-svn trunk <-- from uniTwo  
         `--o--o-o--o git mybranch  <-- from Laptop

After cloning the repo should be able to pull branches from Laptop. 克隆后,回购应该能够从笔记本电脑拉分支。

I have tried: on uniOne: git-svn clone uniTwo, git remote add Laptop, but then git fetch wants to get the whole thing from Laptop. 我试过了:在uniOne上:git-svn克隆uniTwo,git远程添加Laptop,但是git fetch想要从Laptop获得整个东西。 I thought maybe using git clone --depth x Laptop and then graft them together might work but it still requires all of the source files to be transfered Laptop->uniOne, not just the changes. 我认为也许可以使用git clone --depth x Laptop,然后将它们嫁接在一起,但这仍然需要将所有源文件传输到Laptop-> uniOne,而不仅仅是更改。 I could try to export all patches from Laptop and apply them on top of a fresh svn checkout then get it to track the branch on my Laptop (if that is possible) but it would be easier to wait until I am next at uni and then just clone normally. 我可以尝试从笔记本电脑导出所有补丁,并在新的svn checkout上应用它们,然后让它跟踪我的笔记本电脑上的分支(如果可能的话),但是等到我下次去uni时再方便些,然后正常克隆即可。

Let's define your repositories: 让我们定义您的存储库:

  • git-svn <-- this is the Subversion repository at University git-svn <-这是大学的Subversion存储库
  • uni/master <-- this is a Git repository at your University. uni / master <-这是您大学的Git存储库。 This is jus a "fetching repository" that gets the latest history from the Subversion repo. 这是从Subversion存储库获取最新历史记录的“获取存储库”。
  • laptop/master <-- This is the Git repository on your laptop. laptop / master <-这是笔记本电脑上的Git存储库。 This is where you work. 这是您工作的地方。

I would suggest the following setup: 我建议以下设置:

Create uni/master by doing git svn clone of git-svn . 通过执行git-svn的 git svn clone创建uni / master Automatically or regularly update uni/master with the latest changes from git-svn by running git svn rebase (trigger with a commit hook, cron-job, or manually every time you're at Uni). 通过运行git svn rebase (使用提交挂钩,cron-job或每次您在Uni时手动触发),自动或定期用git-svn的最新更改更新uni / master

Create laptop/master by cloning uni/master . 通过克隆uni / master创建笔记本电脑 / master Here you can commit locally as often as you want. 在这里,您可以根据需要进行本地提交。 When you are at University, get the latest changes from uni/master by running git pull --rebase (you always have to do --rebase to keep history linear, because SVN won't understand git-branches). 在上大学时,请通过运行git pull --rebaseuni / master获得最新更改(您总是必须执行--rebase才能使历史保持线性,因为SVN无法理解git-branches)。

When you want to push changes from your laptop back to git-svn , you have to configure the git-svn remote on your laptop/master first: 当您要将更改从笔记本电脑推送回git-svn时 ,必须首先在笔记本电脑/主服务器上配置git-svn遥控器:

git svn init https://url.to.uni-svn-repo

Now you can push your latest changes back to uni-svn with git svn dcommit . 现在,您可以使用git svn dcommit将最新更改推回uni-svn Note that you might have to update the reference to the latest commit in uni/master first. 请注意,您可能必须先将对引用的更新更新为uni / master中的最新提交。 first: 第一:

git update-ref refs/remotes/git-svn refs/remotes/uni/master

DO NOT attempt to push from your laptop/master to uni/master . 请勿尝试从笔记本电脑/主机推送到uni / master This will only bring chaos as the rebasing/rewriting history will just confuse Git when it tries to sync with git-svn again. 这只会带来混乱,因为在重新尝试与git-svn同步时,重新设置/重写历史记录只会混淆Git。

See also http://www.tfnico.com/presentations/git-and-subversion where I've started collecting up a bunch of tips for working with Git and SVN together. 另请参见http://www.tfnico.com/presentations/git-and-subversion ,在这里我开始收集了一些与Git和SVN一起使用的技巧。

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

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