Git format-patch for svn compatibility?

Is there a way to get a patch created using git format-patch compatible with svn so that I can send it to svn repo?

I work with svn repo on github and want to post my changes back to the main repo. I need to create a patch in order to do this, however the patch cannot be applied with git formats that patch differently from svn. Is there any secret I haven't discovered yet?

UPDATE:. Although there is currently no script or native git for this, I managed to find a message from earlier this year on how to manually execute this. I followed the instructions and was successful in getting my git patches for working with svn.

If someone can strike at writing a script to accomplish this and contribute to the git project, I will be very grateful to everyone.

http://kerneltrap.org/mailarchive/git/2008/1/15/570308/thread#mid-570308

+89
git svn format-patch
Apr 2 '09 at 3:45
source share
8 answers

I always need to do this on Google, but the way I found it works fine (for me):

  • Create a patch using git diff --no-prefix master..branch > somefile.diff , the main part and branch are optional, depending on how you want to get your differences.
  • Send it everywhere and apply using patch -p0 < somefile.diff .

Everything seems to work just fine for me and seems to be the easiest method I've come across.

+80
Nov 14 '12 at 11:01
source share

The short answer is patch -p1 -i {patch.file} .

See this blog post for details: Creating Subversion patches with git .

+20
Mar 24 2018-12-12T00:
source share

Here's a script helper for making a difference with the latest set of svn changes and this commit: http://www.mail-archive.com/dev@trafficserver.apache.org/msg00864.html

 #!/bin/sh # # git-svn-diff # Generate an SVN-compatible diff against the tip of the tracking branch TRACKING_BRANCH=`git config --get svn-remote.svn.fetch | sed -e 's/.*:refs\/remotes\///'` REV=`git svn find-rev $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH)` git diff --no-prefix $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH) $* | sed -e "s/^+++ .*/& (working copy)/" -e "s/^--- .*/& (revision $REV)/" \ -e "s/^diff --git [^[:space:]]*/Index:/" \ -e "s/^index.*/===================================================================/" 
+17
Nov 29 '10 at 21:16
source share

SVN probably cannot understand the output of git diff -p , but you can resort to brute force:

  • Make two clones of your repo
  • In one clone check your latest stuff.
  • In another clone check, which is equivalent to svn upstream. If you planned ahead, you have a copy of svn upstream in your branch, or you have flagged the latest version of svn. If you haven’t planned yet, use date or gitk to find the git SHA1 hash that comes closest to svn state.
  • Now figure out the real patch by running diff -r on the two clones.
+11
Apr 02 '09 at 4:20
source share

Subversion <1.6 does not support fixes. Subversion 1.7 seems to allow patches to be applied, and the git / hg extensions for the unified diff are on our TODO list.

+11
Dec 22 '09 at 14:20
source share

This is really a feature request in early 2008

Linus Torvalds said at the time:

So I would say that you need something stronger to say “don't do git diff”, and that should also prevent detection of renaming at least.
Quite frankly, any program that is so stupid as not to accept the current git patches (i.e. TortoiseSVN), then we should not damn well just disable its most trivial part. We need to make sure that we have not included any of the pretty important extensions:
even if ToirtoiseSVN ignores them, if ignored means that he misunderstands diff, he should not be allowed at all.

Maybe that's why

  git-format-patch: add --no-binary to omit binary changes in the patch. 

was introduced in Git1.5.6 in May / July 2008 (I have not tested it yet)

+4
Apr 02 '09 at 4:20
source share

Make sure your changes are committed and reinstalled over the local git branch from git bash run:

git show --pretty → myChangesFile.patch

0
Apr 23 '13 at
source share

Nicholas's accepted answer works fine unless a) the binaries exist in diff or b) you work in windows Git and have directories with spaces. To get this solution, I had to add a Git diff nested command to ignore the binaries and sed command to avoid spaces. It's a little cumbersome to write, so I created an alias:

 [alias] svnpatch = "!f() { git diff --name-only --no-prefix master...$1 | grep -Ev \"\\.sdf|\\.Doc|\\.dll|\\.zip|\\.exe\" | sed 's_\\s_\\\\\\\\ _g' | xargs git diff --no-prefix master...$1 > $1.patch; echo "Created $1.patch"; }; f" 

If you then type:

 git svnpatch Feature123 

... Feature123.patch patch file will be created with the differences between the merge base of the master server and the Feature123 branch.

0
Jun 16 '17 at 3:28
source share



All Articles