30

On windows, I have two source files and want to create a patch with difference, like this one. But I'm unsure, what format this patch is and what app to use in order to create it? GNU diff output is very different from the patch I can see in the link above.

Borislav Ivanov
  • 4,684
  • 3
  • 31
  • 55
grigoryvp
  • 40,413
  • 64
  • 174
  • 277
  • 1
    UnixUtils package for Windows does not work for binary files. Running "diff -u oldfile newfile >patchfile" gives a patch file with a single line of text, "Binary files file1.mp3 and file2.mp3 differ". (Unable to add comment due to being blocked by not having any reputation points. NOT user friendly!) – Stan Duncan Dec 28 '17 at 09:22

8 Answers8

27

Try WinMerge. You'll find a patch generator in the "Tools" menu.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • 2
    Although the OP is talking about source code which implies he is talking of text files I would like to add the information that WinMerge is not able to produce patch files for binary files. – Marged Mar 09 '16 at 17:14
24

Thanks, PhiLho & Lukáš! The diff program from UnxUtils works great under Windows 7 to generate the patch file:

diff -u oldfile newfile >patchfile

Likewise, the patch program from UnxUtils works great to apply the patch:

patch -u oldfile patchfile
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Dave Burton
  • 2,960
  • 29
  • 19
17

The output format is called "unified diff", it can be generated using diff -u.

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126
10

WinMerge is the best tool for windows. To create a patch file, you need to do the following:

File>Open

-- Here you open the files for which you are generating patch file.

Tools>Generate Patch

-- Here you specify the path where to save the patch file. And WinMerge will save patch file for you.

Pupil
  • 23,834
  • 6
  • 44
  • 66
  • Note: The "normal" patch style uses angle brackets < > as line action indicators. The "unified" style uses + and - (like patches on drupal.org). – As If Mar 28 '19 at 20:26
  • You can also drag & drop two files (at once) to WinMerge. And WinMerge includes the full path to the files in the patch file. – PeterCo Jul 02 '20 at 12:02
7

WinMerge (http://winmerge.org/) is what you need. You also can compare whole file trees with this tool, which is an absolute must-have for some people.

sha1
  • 71
  • 4
  • 2
4

The UnxUtils package offers lot of useful Unix tools for Windows, with a minimal impact on Windows installation (unzip, add location to path, use it).
It has a diff.exe

PhiLho
  • 40,535
  • 6
  • 96
  • 134
1

In Beyond Compare 4 you can generate a unified diff by selecting the 'Session' > 'Text Compare Report...' menu item and then selecting 'Patch' for the layout and 'Unified diff' for the patch style. Then save the output to file, or to the clipboard.

Ian Brumby
  • 11
  • 1
0

I've also made a tool to generate patch files (like WinMerge html format) between two sets of changesets/folders/commits (as a zip downloaded from github or azure or just folders sitting in your drive) since currently WinMerge does NOT support path file generation from command-line to support automation.

use it like:

python diff_generator.py --c1 "path_to_file1.zip" --c2 "path_to_file2.zip" [--git]

or

python diff_generator.py --c1 "path_to_folder1" --ddc1 --c2 "path_to_folder2" --ddc2
ClassY
  • 744
  • 5
  • 20