13 March 2025

This snippet demonstrates how to generate a unified diff (.patch file) between two files using diff -u and apply the patch using patch -p1. This method is useful for tracking changes and updating files efficiently.

Source code viewer
  1. # Creating and Applying a Patch-Compatible Diff
  2.  
  3. # This generates a unified diff (patch) between two files
  4. diff -u original.txt modified.txt > changes.patch
  5.  
  6. # Apply the generated patch to the original file
  7. patch -p1 < changes.patch
Programming Language: Bash