65

Is it possible to retrospectively create a patch? The Tortoise SVN client we are using gives us the option to create a patch instead of (or during) a commit.

I would like to work on the fix using the trunk, check it in and have the build server run all its tests and metrics to confirm that the fix is acceptable. I would then like to be able to select a few revisions (if the first attempt at fixing it only got us part way there) and create a patch file from the files that have changed.

I can then take the patch and apply it to a few other branches. Is this possible?

2
  • 4
    You can create a patch by executing the svn diff command between any two versions in SVN. Commented Aug 22, 2012 at 12:08
  • Note that in other use cases where one needs to patch after a commit, if this patch is for another branch, you can just merge specific revisions or a range of revisions, which is more SVN-healthy (shows up in the log, single commit or set of commits and not duplicates, etc.). Commented Nov 15, 2017 at 15:50

4 Answers 4

114

Show Log, select the revisions, right-click, "show unified diff".

Sign up to request clarification or add additional context in comments.

3 Comments

So is a patch file just a unified diff or does "save as patch" alter the contents in some way?
I had the same problem as Ilya - I couldn't apply the unified diff (to a different branch) after I saved it as a patch. I managed to fix the problem - the unified diff had some absolute paths in, whereas normal patch files didn't. I did a search and replace to remove the absolute paths and then it worked correctly.
"show unified diff" => "show changes as unified diff" in new Tortoise SVN version
2

if you have problem with paths, you can show diff on every file separately

Comments

0

You can also use WinMerge on Windows if you want to compare two files from different branches:

  1. Check out each branch
  2. Mark the two files that should be compared
  3. Compare via WinMerge
  4. Then click: Tools -> Generate Patch

By this you can create a patch for already committed files from different branches.

Comments

0

I tend to use the svn diff command line to create patches. As such, the following examples could be used, but they rely upon you knowing the revision number - which shouldn't be too difficult to ascertain.

For the purposes of this answer, let's assume the following:

  • The revision number of your commit is 1234.
  • Your SVN repository is located at https://mySvnServer/myRepository/trunk.
  • You will place your patches in C:\Path\To\Patches\.

Create a patch of just revision 1234. Note -c 1234.

svn diff -c 1234 https://mySvnServer/myRepository/trunk > "C:\Path\To\Patches\1234.patch"

Create a patch of all revisions between your commit and the head (latest commit). Note -r 1234:HEAD.

svn diff -r 1234:HEAD https://mySvnServer/myRepository/trunk > "C:\Path\To\Patches\1234_head.patch"

As far as I know, there isn't a single line method of creating a patch from multiple non-consecutive revision numbers without creating a branch, merging in the desired revisions individually, and then performing a svn diff (similar to above) to create a patch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.