Git Patch to Subversion

Recently a Subversion repo I was using got corrupted. Total crisis was averted by good backups and an hour later we were back up and running. Unfortunately we lost the last 3 commits. Lucky for us I was using Git as my SVN client. It took a bit of messing around to pull my commits out of Git and apply them to Subversion, but in the end Git saved the day. I’ll retrace my steps in case anyone else has similar issues.

  1. Find out which commits you need
  2. Use git command line and create your diff:
    # git diff --no-prefix <r-1> <r> > Commit-<r>.patch

    Where <r> represents the hash for your target commit and <r-1> represents the hash of the commit before it.

  3. Go to the subversion working root directory
  4. Apply the patch for the version
    # patch -p0 < <Path-To-PatchFile>
  5. Commit using the old commit message from your Git history

Repeat steps 2-5 for each commit found in step 1.

I had to insert an additional step when I did this. My paths contained spaces (not my doing) and patch didn’t seem to like that. I removed the path from the filename in each patch and then ran the patch in the parent directory of the file. Hopefully this doesn’t happen to you.

Leave a Reply

Your email address will not be published. Required fields are marked *

17 − eight =