diff options
Diffstat (limited to 'content/articles/crear-parches-con-git.en.md')
-rw-r--r-- | content/articles/crear-parches-con-git.en.md | 129 |
1 files changed, 64 insertions, 65 deletions
diff --git a/content/articles/crear-parches-con-git.en.md b/content/articles/crear-parches-con-git.en.md index ac1e28d..daf6d40 100644 --- a/content/articles/crear-parches-con-git.en.md +++ b/content/articles/crear-parches-con-git.en.md @@ -42,7 +42,7 @@ So, to modify our script, text or source code, we must first create the directory `a` and `b` :::bash - mkdir a b + $ mkdir a b In directory `a` we will put the unmodified file or files, and in directory `b` the modified one. @@ -51,7 +51,7 @@ and in directory `b` the modified one. Run: ```bash -git diff --no-prefix --no-index --no-renames --binary a b > patched.patch +$ git diff --no-prefix --no-index --no-renames --binary a b > patched.patch ``` + --no-prefix: Do not show any source or destination prefix. @@ -71,7 +71,7 @@ depending on the case. then we will use this command: :::bash - patch -p1 -i /ruta/del/parche.diff + $ patch -p1 -i /ruta/del/parche.diff 2. With binary files: That is, things like already compiled executable programs, PNG images, JPEG, Gif, etc. other than plain text. In general you will be able @@ -79,7 +79,7 @@ depending on the case. "GIT binary patch". In this case we will apply the patch as follows: :::bash - git apply -v /ruta/del/parche.diff + $ git apply -v /ruta/del/parche.diff ## The issue with diff and not making directories a and b Now, going back to what I said earlier about why this is important, @@ -107,50 +107,49 @@ In the first one, I will create the files that I put as an example **script.sh:** -```bash - #!/bin/bash - echo "Hello world" -``` + #!bash + #!/bin/bash + echo "Hello world" **script.sh.new:** -```bash - #!/bin/sh - echo "Hello world" - echo "This is a patched file :D" -``` + #!sh + #!/bin/sh + echo "Hello world" + echo "This is a patched file :D" + Now we will do what most internet tutorials tell you to do: :::bash - diff -u script.sh script.sh.new + $ diff -u script.sh script.sh.new And it looks like this: -```diff ---- script.sh 2018-03-16 15:52:49.887087539 -0300 -+++ script.sh.new 2018-03-16 15:53:02.490420209 -0300 -@@ -1,2 +1,3 @@ --#!/bin/bash -+#!/bin/sh - echo "Hello world" -+echo "This is a patched file :D" -``` + #!diff + --- script.sh 2018-03-16 15:52:49.887087539 -0300 + +++ script.sh.new 2018-03-16 15:53:02.490420209 -0300 + @@ -1,2 +1,3 @@ + -#!/bin/bash + +#!/bin/sh + echo "Hello world" + +echo "This is a patched file :D" + Everything apparently fine, but now let's apply that patch ```bash $ diff -u script.sh script.sh.new | patch -p1 -i /dev/stdin ``` -```diff -can't find file to patch at input line 3 -Perhaps you used the wrong -p or --strip option? -The text leading up to this was: --------------------------- -|--- script.sh 2018-03-16 15:52:49.887087539 -0300 -|+++ script.sh.new 2018-03-16 15:53:02.490420209 -0300 --------------------------- -File to patch: -``` + #!diff + can't find file to patch at input line 3 + Perhaps you used the wrong -p or --strip option? + The text leading up to this was: + -------------------------- + |--- script.sh 2018-03-16 15:52:49.887087539 -0300 + |+++ script.sh.new 2018-03-16 15:53:02.490420209 -0300 + -------------------------- + File to patch: + It fails being that I am in the same directory as `script.sh{.new}`, so this is fixed using the create directories `a/` and `b/` hack. However, this does not turn out point 2 and 3. Let's go for it. @@ -169,17 +168,17 @@ Okay, now let's make the patch with diff: $ diff -ur a b ``` -```diff -Sólo en b: binary_file.bin -diff -ur a/script.sh b/script.sh ---- a/script.sh 2018-03-16 15:37:27.513802777 -0300 -+++ b/script.sh 2018-03-16 15:41:17.717123987 -0300 -@@ -1,2 +1,3 @@ --#!/bin/bash -+#!/bin/sh - echo "Hello world" -+echo "This is a patched file :D" -``` + #!diff + Only in b: binary_file.bin + diff -ur a/script.sh b/script.sh + --- a/script.sh 2018-03-16 15:37:27.513802777 -0300 + +++ b/script.sh 2018-03-16 15:41:17.717123987 -0300 + @@ -1,2 +1,3 @@ + -#!/bin/bash + +#!/bin/sh + echo "Hello world" + +echo "This is a patched file :D" + And what is said in point 2 is true, it does not put the new file, it tells you "Only in b" or if there is a file that is in `a/` but not in `b/` (that is to say, surely you removed it from your fork), you will @@ -194,27 +193,27 @@ See what happens if I use `git` instead of `diff`: $ git diff --no-prefix --no-index --no-renames --binary a b ``` -```diff -diff --git b/binary_file.bin b/binary_file.bin -new file mode 100644 -index 0000000000000000000000000000000000000000..1ce3c1c596d7a7f400b0cc89bda5a41eed2780c5 -GIT binary patch -literal 73 -pcmd-HXHZUIU{c}EWl|AfLZWk+R0P|Ad@#)bSHb~R0-{lr003gr3L5|b - -literal 0 -HcmV?d00001 - -diff --git a/script.sh b/script.sh -index da049c4..3d351f5 100644 ---- a/script.sh -+++ b/script.sh -@@ -1,2 +1,3 @@ --#!/bin/bash -+#!/bin/sh - echo "Hello world" -+echo "This is a patched file :D" -``` + #!diff + diff --git b/binary_file.bin b/binary_file.bin + new file mode 100644 + index 0000000000000000000000000000000000000000..1ce3c1c596d7a7f400b0cc89bda5a41eed2780c5 + GIT binary patch + literal 73 + pcmd-HXHZUIU{c}EWl|AfLZWk+R0P|Ad@#)bSHb~R0-{lr003gr3L5|b + + literal 0 + HcmV?d00001 + + diff --git a/script.sh b/script.sh + index da049c4..3d351f5 100644 + --- a/script.sh + +++ b/script.sh + @@ -1,2 +1,3 @@ + -#!/bin/bash + +#!/bin/sh + echo "Hello world" + +echo "This is a patched file :D" + Now I did consider the non-existent binary file in `a/` but tangible in `b/`. Note that in this particular case, as I explained earlier, when dealing with binary files that only git supports (see the message "GIT binary patch") you |