At Eljakim (my new employer), work repositories are all svn (lowest common denominator), but several of us access them via git-svn. I’ve created a couple of new ones recently, but thanks to timezones, I never get an svn repo until I’ve already done a day’s work (in git). Getting those commits into svn without losing history is a simple thing when you know how – but when I googled, all I saw were strange and crazy hacks involving arcane commands I didn’t understand. So, here’s the easy way:
- Check out the svn repo
- Make a folder for your work (assuming it’s not already there)
- Check out just that folder
- Connect it to the git repo
- Rebase your work on top of svn
- Clean up the temp file (is thre a way to just commit an empty dir in git?)
- And send it to the server!
- Switch back to the primary repo (optional)
git svn clone https://url.to/svn-repo
cd svn-repo
mkdir chani
touch chani/temp
git add chani/temp
git ci
git svn dcommit
cd ..
git svn clone https://url.to/svn-repo/chani merge-repo
cd merge-repo
git remote add mygit /path/to/git-repo
git fetch mygit
git checkout -b mymerge mygit/master
git rebase master
git checkout master
git merge --ff-only mymerge
git rm temp
git ci
git svn dcommit
cd ..
rm -rf merge-repo
cd svn-repo
git svn rebase
Of course, you don’t have to delete the merge repo, you could keep using it as your primary repo – but the way things are set up here I always end up wanting my checkout to be a level above that. :)
Edit: Also, make sure you move or delete the original git repo once the commits are safely in svn. I spent half the day continuing to work in the pure git repo after blogging this… >.< oh well, at least I just had to copy&paste off my blog to fix it. :P
Hi, I don’t fully get, what is the purpose of the second git merge-repo?
I’m also using git-svn, and typically, I make a “git svn clone” and then just happily use “git svn dcommit” and “git svn fetch” or “git svn rebase”.
That should be enough when working on SVN repositories from git.
umm.. the point is I have a git repo. that I want to import. hence “import from git into svn” and not “commit to an svn project with git-svn”
I think one can’t have totally empty directories in git, but you can add an empty .gitignore file to temp and have it almost emtpy
Yeah, the “official” way of having an empty directory is, as Kevin said, to use a dotfile. I usually use .gitignore, but you’ll also often see .gitkeep, which is arguably more sensible. These files are very important in the Ruby on Rails community, which is heavily into git in general, and needs empty directories quite frequently for generated log files, pid files, cache etc…
I think it’s much more simple just to install SubGit (from subgit.com) into your SVN repository (of course, if you have an access to the server, do you?),
and just to use pure Git interface.
Of course, then you will need to setup a Git access, here’s an example how to do it with git-http-backend:
http://subgit.com/documentation/svn2git.html
neat! I didn’t know about that. :) I don’t have access to the server, of course, but perhaps I can convince whoever does to install that sometime…