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. I'd like to minimise the amount of home<->uni traffic by maximising uniOne<->uniTwo traffic.
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:
--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. 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. I could tr开发者_JAVA百科y 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.
Let's define your repositories:
- git-svn <-- this is the Subversion repository at University
- uni/master <-- this is a Git repository at your University. This is jus a "fetching repository" that gets the latest history from the Subversion repo.
- laptop/master <-- This is the Git repository on your laptop. This is where you work.
I would suggest the following setup:
Create uni/master by doing git svn clone
of git-svn.
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).
Create laptop/master by cloning uni/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).
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 init https://url.to.uni-svn-repo
Now you can push your latest changes back to uni-svn with git svn dcommit
. Note that you might have to update the reference to the latest commit in uni/master first. first:
git update-ref refs/remotes/git-svn refs/remotes/uni/master
DO NOT attempt to push from your laptop/master to 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.
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.
精彩评论