5

So I set up a git-svn repo and pushed it to github. But if one clones it there is no svn config in the clone.
The diff between the repository I pushed and the one I cloned from github just after I pushed is :

enter image description here

The one I pushed (the svn clone with the svn info) is on the right - the clone from github is on the left
Which of those (folders/files (or config sections)) should I share to have people setup git-svn as I have ? In the sense that they clone and then copy paste those files (and possibly run git svn rebase) and they have the same setup as I have. I have cloned all the branches and tags of the svn repo as remote branches also and I would like to share those too. Ideally those files should still be valid even after I (we) start pushing/dcommiting between the git and svn repo

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361

1 Answers1

2

This seems to work for me:

git clone your-existing-git-repo new-cloned-repo
cd new-cloned-repo
git fetch origin refs/remotes/*:refs/remotes/*
git init
git svn init -s "svn://your-svn-server/your-svn-repo/your-svn-project"
git svn fetch
git checkout master
git svn rebase

While the above works, I have found the below makes a repo with a .git/config file that is identical to my original (no origin remote attachment to master branch).

mkdir new-cloned-repo
cd new-cloned-repo
git init --bare .git
git remote add backup your-existing-git-repo
git fetch backup refs/remotes/*:refs/remotes/*
git fetch backup refs/heads/*:refs/heads/*
git fetch backup refs/tags/*:refs/tags/*
git init

# update SVN references
git svn init -s "svn://your-svn-server/your-svn-repo/your-svn-project"
git config svn.authorsfile your-authors-file.txt
git svn fetch

git checkout master
git svn rebase
git svn show-ignore >> .git/info/exclude

This should clone all Git commits git clone/git fetch and remote branches (all SVN branches/tags that your existing repo knows about) git fetch origin refs/remotes/*, update the SVN connection info git svn init and then update the SVN revision to Git commit mappings via the git svn fetch.

The git svn init -s assumes you are storing stuff in the normal SVN way under your-svn-project (trunk, branches/*, tags/*).

I'm not sure if the git init is needed, but I am sure that it doesn't harm anything if it isn't needed. Also, the git checkout master is likely redundant, but harms nothing.

Shadow Man
  • 3,234
  • 1
  • 24
  • 35
  • The above can easily be copied into a `.bat` file or `.sh` script. I have made a shell script for myself which checks to make sure the git and svn repositories exist by checking return values of `git ls-remote "$EXISTING_GIT_REPO" > /dev/null 2>&1` and `svn ls "$EXISTING_SVN_REPO" 2> /dev/null | grep -q trunk` respectively and also checks to make sure that the new repo directory does not exist before doing anything. – Shadow Man Aug 31 '13 at 00:49
  • Thanks - `your-existing-git-repo` is the one I pushed to the server or the one I have locally (the one with the svn config in it) ? If it is the one I pushed to the server it has no info on the remotes. Re: `-s` - the clone command I used is [here](http://stackoverflow.com/questions/17910674/extra-branches-created-by-git-svn-clone) - I guess I should use this where you use `git svn init -s` – Mr_and_Mrs_D Aug 31 '13 at 16:40
  • I created a repo from `git svn clone -s ...` and backed it up with a mirror `git push my-backup-repo --mirror`. I use the above to create a copy of the first from the mirrored backup. In this scenario `your-existing-repo` is my backed up mirror (which knows nothing about the svn server but has all of the branches and tags due to the `--mirror`). We are assuming you lost your original svn clone or are attempting to create a new one anyway from your git mirror. – Shadow Man Sep 01 '13 at 07:49
  • PS - I also got it to work by pulling from my original svn clone to the new blank git repo. But my main purpose was to have a way of backing up my clone and restoring all svn links and history from my backup. The `git svn fetch` does hit the svn server but does not download anything that the original `your-existing-repo` already had (just builds the svn metadata linking revisions to sha1 hashes -- takes seconds to run rather than hours like the original `git svn clone` did). It will download new svn commits though. – Shadow Man Sep 01 '13 at 08:00
  • I asked a similar question in case this helps at all: http://stackoverflow.com/questions/18006757/how-to-clone-a-git-repo-with-all-branches-and-tags-from-refs-remotes – Shadow Man Sep 01 '13 at 08:35
  • Ok - thanks for following up - "or are attempting to create a new one anyway from your git mirror" - that's what I'm trying to do (have collaborators clone the online repo and then recreate the git svn config - did not know about the --mirror so my `your-existing-repo` was a plain push) - will go through your answer in detail ASAP – Mr_and_Mrs_D Sep 01 '13 at 09:22
  • After more testing, I have found that `git config remote.backup.fetch do_not_fetch_from_backup` and `git config remote.backup.push '+refs/remotes/*:refs/remotes/*'` allows me to `git push backup` without `--mirror` and still maintain all remote SVN refs using the above script (however, I haven't tested this to see how well -- or even if -- it pushes local refs). – Shadow Man Sep 04 '13 at 20:52
  • 1
    Well - both solutions involve svn fetch. Tried both and I think they take as much time as a fresh clone (never completed due to net hanging up) - am I right ? – Mr_and_Mrs_D Jan 02 '14 at 04:26
  • SVN doesn't download all history, so "cloning" an SVN repo is fast since it only downloads the latest commit state of your master branch. With Git, it tries to download all history on a clone. So if your repo has lots of history or large binary files in it, then it may not look like much of a time savings for you. However, if you had to do the stuff I had to do (to merge history that spans multiple SVN paths for instance) then you are going to save all that time and effort by just backing up and restoring from your cleaned-up new git repo and hooking that into SVN. – Shadow Man Jan 08 '19 at 00:37