Reputation: 61041
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.
Upvotes: 54
Views: 28792
Reputation: 61041
What I actually did for was:
cd /path/to/svn/repo
svn diff -r 125 > /tmp/patch.diff
cd /path/to/git/repo
patch -p0 < /tmp/patch.diff
Upvotes: 55
Reputation: 30662
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
Upvotes: 8
Reputation: 5451
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.
Upvotes: 1
Reputation: 392911
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.
Upvotes: 5
Reputation: 5097
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.
Upvotes: 2
Reputation: 7924
Try:
svn diff | patch -d /path/to/git/repo -p0
See svn help diff
if you want to export a specific revision's diff.
Upvotes: 19