Last active
May 1, 2023 22:21
-
-
Save Risto-Stevcev/8d2ef4f00f8fca90264591cea7a3dde4 to your computer and use it in GitHub Desktop.
Patching using the `patch` command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.