How to apply SVN diff to Git?

SvnGitVersion ControlPatch

Svn Problem Overview


I have my projects in 2 repositories. One under SVN and one under Git. Whenever I change something in SVN I want to do the same thing to the Git repository.

Say I make a change to SVN repository, producing revision 125. How would I apply these same changes to my Git repository (assuming my Git repository is up to date with revision 124).

Thank you.

Svn Solutions


Solution 1 - Svn

What I actually did/looking for was:

cd /path/to/svn/repo
svn diff -r 125 > /tmp/patch.diff
cd /path/to/git/repo
patch -p0 < /tmp/patch.diff

Solution 2 - Svn

Try:

svn diff | patch -d /path/to/git/repo -p0

See svn help diff if you want to export a specific revision's diff.

Solution 3 - Svn

If you are going to generate a patch in SVN and apply it with Git later, don't forget to use --git command-line option:

> --git > > Enables a special output mode for svn diff designed for cross-compatibility with the popular Git distributed version control > system.

For example, run

svn diff --git -r 125 > /tmp/patch.diff

Solution 4 - Svn

Why does no one like git-svn? I cannot assume no-one knows about it.

There is git-svn (and git-hg and git-cvs and git-bzr afaict). At least with git-svn you can simply do

git svn clone --stdlayout http://myrepo/root here

using -s (--stdlayout) assumes standard trunk/ branches/ tags/ layout, but you can have it any which way (man git-svn).

The mapping is bidirectional, so you can push and pull as with a native (git) remote. No questions asked.

Solution 5 - Svn

Besides using patch as mentioned above you could also consider setting up a post-commit hook so you don't have to do this every time you commit something new.

Solution 6 - Svn

The below worked for me.

Source:How to create and apply a patch with Git

First, take a look at what changes are in the patch. You can do this easily with git apply

git apply --stat fix_empty_poster.patch

Note that this command DOES NOT apply the patch, but only shows you the stats about what it’ll do. After peeking into the patch file with your favorite editor, you can see what the actual changes are.

Next, you’re interested in how troublesome the patch is going to be. Git allows you to test the patch before you actually apply it.

git apply --check fix_empty_poster.patch

If you don’t get any errors, the patch can be applied cleanly . Otherwise you may see what trouble you’ll run into.

To apply the patch, I’ll use git am instead of git apply. The reason for this is that git am allows you to sign off an applied patch. This may be useful for later reference.

git am --signoff < fix_empty_poster.patch

Applying: Added specs to test empty poster URL behaviour
Applying: Added poster URL as part of cli output

Okay, patches were applied cleanly and your master branch has been updated. Of course, run your tests again to make sure nothing got broken.

In you git log, you’ll find that the commit messages contain a “Signed-off-by” tag. This tag will be read by Github and others to provide useful info about how the commit ended up in the code.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndriy DrozdyukView Question on Stackoverflow
Solution 1 - SvnAndriy DrozdyukView Answer on Stackoverflow
Solution 2 - SvnMattJView Answer on Stackoverflow
Solution 3 - SvnbahrepView Answer on Stackoverflow
Solution 4 - SvnseheView Answer on Stackoverflow
Solution 5 - SvnFederico BuilesView Answer on Stackoverflow
Solution 6 - SvnAbhishek BediView Answer on Stackoverflow