Create SVN patch after commit
Asked Answered
P

4

64

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?

Palikar answered 22/8, 2012 at 11:30 Comment(2)
You can create a patch by executing the svn diff command between any two versions in SVN.Maximo
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.).Deibel
M
114

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

Margetmargette answered 22/8, 2012 at 15:20 Comment(3)
So is a patch file just a unified diff or does "save as patch" alter the contents in some way?Palikar
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.Cyclops
"show unified diff" => "show changes as unified diff" in new Tortoise SVN versionUncivilized
S
2

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

Sinner answered 26/7, 2013 at 13:33 Comment(0)
S
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.

Statehood answered 5/8, 2014 at 7:20 Comment(0)
G
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.

Gloxinia answered 1/3, 2022 at 12:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.