Updating a Configuration File with a Patch

Apply a unified diff patch to update a configuration file. Learn how to handle YAML, JSON, and INI config file patches safely.

Common Use Cases

Detailed Explanation

Patching Configuration Files

Configuration files are a common target for patches. Whether it is a YAML deployment config, a JSON settings file, or an INI configuration, the process is the same: the patch targets specific lines by their context.

Example: Updating a YAML Config

Original docker-compose.yml:

version: "3.8"
services:
  web:
    image: nginx:1.21
    ports:
      - "80:80"
    environment:
      - NODE_ENV=development

Patch:

--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,7 +3,9 @@
 services:
   web:
-    image: nginx:1.21
+    image: nginx:1.25
     ports:
       - "80:80"
+      - "443:443"
     environment:
-      - NODE_ENV=development
+      - NODE_ENV=production
+      - LOG_LEVEL=info

Why Patches for Config Files?

  1. Reproducibility — share exact changes with team members
  2. Audit trail — patches clearly show what changed and why
  3. Automation — patches can be scripted into deployment pipelines
  4. Safety — unlike full file replacement, patches only modify targeted lines

Handling Indentation

Configuration files like YAML are whitespace-sensitive. The patch must match the exact indentation of the original file, including whether spaces or tabs are used. If your patch fails to apply, check that:

  • Leading whitespace matches exactly
  • No tabs have been converted to spaces (or vice versa)
  • The line endings (LF vs CRLF) are consistent

Use Case

Your DevOps team distributes configuration updates as patches rather than full file replacements. This ensures that local customizations are preserved while targeted settings are updated.

Try It — Diff Patch Applier

Open full tool