Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Last active May 1, 2023 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risto-Stevcev/8d2ef4f00f8fca90264591cea7a3dde4 to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/8d2ef4f00f8fca90264591cea7a3dde4 to your computer and use it in GitHub Desktop.
Patching using the `patch` command
diff -bur foo/baz.txt bar/baz.txt
--- foo/baz.txt 2023-05-01 18:20:09.887623152 -0400
+++ bar/baz.txt 2023-05-01 18:20:09.887623152 -0400
@@ -1 +1 @@
-norf
+qux
#!/bin/sh
mkdir foo bar
echo worble > foo/foo.txt
cp foo/foo.txt bar/
echo norf > foo/baz.txt
echo qux > bar/baz.txt
echo "Tree (Before):"
tree foo/ bar/
echo "Diff (Before):"
diff -bur foo/ bar/
diff -bur foo/ bar/ > foobar.patch
cd foo/
patch -p1 <../foobar.patch
cd ../
echo "Tree (After):"
tree foo/ bar/
echo "Diff (After):"
diff -bur foo/ bar/
@Risto-Stevcev
Copy link
Author

Risto-Stevcev commented May 1, 2023

This is for a whole directory that isn't using the git version of patch. Diffing/patching a single file or a git repo is straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment