Skip to content
  • Florian 
  • 3 min read

Creating a Patch File in Kaleidoscope

Today’s quick tip is a simple but useful for many users.

What is a Patch File?

While primarily used in software development, a patch is a technique applicable to any form of (plain) text file. It is a formal description of changes between two files. Here’s what a simple patch file looks like:

--- original.txt
+++ modified.txt
@@ -1,3 +1,3 @@
 Hello World
- This is the original text.
+ This is the modified text.
 Goodbye World

So What’s the Deal?

The concept of patches dates back to earlier days of computing when users compiled source code for their machines instead of downloading binaries. Transferring entire source files for larger projects was inefficient, so the idea emerged to only transfer the changes made to source files.

Nowadays, this principle can be utilized with Git, saving a patch (e.g. by using Kaleidoscope, or git diff -p) and applying it to to a git working directory using git apply.

Saving a Patch File

When comparing two files, Kaleidoscope allows you to save a patch file that describes all differences.

To do this, click the Share button in the toolbar (or select Kaleidoscope > Share… from the menu) and then Choose Save Patch File… from the sharing popover.

Select a destination and file name, hit the Export button, and a new file will be created, ready to be applied using the patch command line tool, git apply, or some other tool that understands standard patch files.

The Share toolbar button in the Kaleidoscope, offering Save Patch File… and Copy Patch to Clipboard commands. Example shown is System-Color-Picker by Sindre Sorhus on GitHub.

Copying a Patch to the Clipboard

Responding to user requests, we’ve implemented a feature that allows you to skip saving the patch file and instead copy the patch content directly to the clipboard. This can be particularly useful for pasting into a GitHub ticket or a comment on a pull request.

Limitations

A patch must be created from the original unmodified file, not from a derivative. The premise of a patch is that it can be applied to the original file again. Be aware that certain features in Kaleidoscope, such as Ignore Whitespace and Normalize JSON, alter the file content on-the-fly for better comparisons. When either of these features is enabled, creating a patch file is disabled.

Meta Diff

Since patch files are plain text, they can be compared using Kaleidoscope, complete with Syntax Highlighting. Let us know if you have any interesting use cases for this feature.