31

I'm working on a project for which everyone uses SVN as a centralized server and everybody pushes the changes they do on that server. I want to use Git locally and I'm pretty new to git svn. I did a git svn clone of the repository with git svn clone -r HEAD https://svn.repo/app/branch an I want to do an update through git.

I need a 'git pull like' command but to pull from a specific revision of the SVN server repo. Also is there a 'fetch like' command to fetch from a specific revision of the SVN server repo?

I don't have any .svn folders in my cloned project and git remote doesn't give me anything. However I did a git config -l and I get the SVN server's URL, so somehow I'm linked with the SVN server. I don't know how to fetch or pull though.

Thanks!

Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140

2 Answers2

51

Best way to work on a Subversion Repository via Git:

  1. git svn init -s https://svn.repo/app/ myrepo assuming that under https://svn.repo/app/ the repo contains the standard /trunk, branches and tags subdirectories
  2. Do a git svn fetch in myrepo until no more commits are fetched (may take quite some time and sometimes aborts under Windows).
  3. Checkout a specific Subversion branch or trunk via git checkout -b trunk remotes/trunk

Then you can simply browse, hack and commit into your Git Repo containing all Subversion commits and branches.

  • To pull in new commits from SVN use git svn rebase
  • To push your local commits into SVN use git svn dcommit

To jump to a specific Subversion revision you only need to browse the history via git log and search for a commit mirroring the according subversion commit. You can easily spot the Subversion revision in the git-svn-id: line of the commit message. The just use a git checkout <commithash> to explicitly checkout that version.

xyz
  • 115
  • 1
  • 7
bentolor
  • 3,126
  • 2
  • 22
  • 33
  • I realize this is an old question/answer, but when I do `git svn rebase` I'm not getting the actual latest from SVN. It seems that it only sees SVN commits up to the point I did the `git svn clone`. Even when I do `git svn info` it says the latest change was back on the day I did the clone. – mojave Jul 02 '18 at 16:59
  • Hi @mojave. At least `git svn fetch` should contact and fetch new commits from the server. If you rename `.git/svn` this should even refetch the whole history. Did you crosscheck with `svn info `? – bentolor Jul 03 '18 at 07:21
  • Thanks, I did end up recloning because I ran out of time to get the job done. Took 47 hours for the git-svn clone to complete :) – mojave Jul 08 '18 at 20:01
14

A good start :

To fetch new svn commit into your local repo : git svn rebase

To push your local commit to SVN : git svn dcommit

You will probably have to use git stash and git stash pop, before using the two commands above when your working copy has uncommited changes.

Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
Guillaume Darmont
  • 5,002
  • 1
  • 23
  • 35