Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.os.linux > #80262 > unrolled thread
| Started by | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| First post | 2024-08-05 09:35 +0200 |
| Last post | 2024-08-06 07:36 +0200 |
| Articles | 7 — 2 participants |
Back to article view | Back to alt.os.linux
patch a file with the patch command alex <1j9448a02@lnx159sneakemail.com.invalid> - 2024-08-05 09:35 +0200
Re: patch a file with the patch command "J.O. Aho" <user@example.net> - 2024-08-05 12:43 +0200
Re: patch a file with the patch command alex <1j9448a02@lnx159sneakemail.com.invalid> - 2024-08-05 17:33 +0200
Re: patch a file with the patch command "J.O. Aho" <user@example.net> - 2024-08-05 23:05 +0200
Re: patch a file with the patch command alex <1j9448a02@lnx159sneakemail.com.invalid> - 2024-08-06 07:39 +0200
Re: patch a file with the patch command "J.O. Aho" <user@example.net> - 2024-08-06 08:06 +0200
Re: patch a file with the patch command alex <1j9448a02@lnx159sneakemail.com.invalid> - 2024-08-06 07:36 +0200
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2024-08-05 09:35 +0200 |
| Subject | patch a file with the patch command |
| Message-ID | <v8pvb6$iff4$1@dont-email.me> |
Hello everyone. I'll show you my file structure right away ├── middle │ ├── orig │ └── revised └── orig I access the middle directory (the working dir) $ cd middle Let's examine the contents of the files $ cat orig ORIG $ cat ../orig ORIG $ cat revised REVISED Note that the contents of the orig and ../orig files are identical (the two files are identical), but that shouldn't be a big deal. Let's create the patches $ diff -u orig revised > patch-middle $ diff -u ../orig revised > patch-up Let's check the created files (the patches) $ cat patch-middle --- orig 2024-08-02 14:22:59.933683396 +0200 +++ revised 2024-08-02 10:17:25.108469758 +0200 @@ -1 +1 @@ -ORIG +REVISED $ cat patch-up --- ../orig 2024-08-02 14:22:59.937683379 +0200 +++ revised 2024-08-02 10:17:25.108469758 +0200 @@ -1 +1 @@ -ORIG +REVISED It looks ok. Note that for both files (orig and ../orig) the same revision file (revised) was used, but, again, this should not be a big deal. Applying the patches $ patch < patch-middle patching file orig $ patch < patch-up patching file orig Reversed (or previously applied) patch detected! Assume -R? [n] Apply anyway? [n] y Hunk #1 FAILED at 1. 1 out of 1 hunk FAILED -- saving rejects to file orig.rej As you can see with the patch-middle file everything works. While with the patch-up file there is something wrong (Hunk #1 FAILED at 1). Why? Maybe because the ../orig file is in an external directory (a higher level directory "..") than the patch-up file? So? I honestly can't find a plausible explanation.
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2024-08-05 12:43 +0200 |
| Message-ID | <lhbom2FnhvqU1@mid.individual.net> |
| In reply to | #80262 |
On 05/08/2024 09.35, alex wrote:
> Hello everyone.
>
> I'll show you my file structure right away
>
> ├── middle
> │ ├── orig
> │ └── revised
> └── orig
>
> I access the middle directory (the working dir)
>
> $ cd middle
>
> Let's examine the contents of the files
>
> $ cat orig
> ORIG
>
> $ cat ../orig
> ORIG
>
> $ cat revised
> REVISED
>
> Note that the contents of the orig and ../orig files are identical (the
> two files are identical), but that shouldn't be a big deal.
>
> Let's create the patches
>
> $ diff -u orig revised > patch-middle
> $ diff -u ../orig revised > patch-up
>
> Let's check the created files (the patches)
>
> $ cat patch-middle
> --- orig 2024-08-02 14:22:59.933683396 +0200
> +++ revised 2024-08-02 10:17:25.108469758 +0200
> @@ -1 +1 @@
> -ORIG
> +REVISED
>
> $ cat patch-up
> --- ../orig 2024-08-02 14:22:59.937683379 +0200
> +++ revised 2024-08-02 10:17:25.108469758 +0200
> @@ -1 +1 @@
> -ORIG
> +REVISED
>
> It looks ok.
>
> Note that for both files (orig and ../orig) the same revision file
> (revised) was used, but, again, this should not be a big deal.
>
> Applying the patches
>
> $ patch < patch-middle
> patching file orig
>
> $ patch < patch-up
> patching file orig
> Reversed (or previously applied) patch detected! Assume -R? [n]
> Apply anyway? [n] y
> Hunk #1 FAILED at 1.
> 1 out of 1 hunk FAILED -- saving rejects to file orig.rej
>
> As you can see with the patch-middle file everything works.
> While with the patch-up file there is something wrong (Hunk #1 FAILED at
> 1).
>
> Why?
You are trying to "move" the ../orig to revised, the revised file
already exists, so not allowed.
This not how you are supposed to do it, a proper way is to do
├── src
├── orgcopy
| ├── orig
├── revisedcopy
├── orig
cd src
diff -Nurb orgcopy revisedcopy > from_org_to_revised.patch
cd orgcopy
patch -p1 < ../from_org_to_revised.patch
say you made this change
├── src
├── orgcopy
| ├── orig
├── revisedcopy
├── revised
cd src
diff -Nurb orgcopy revisedcopy > from_org_to_revised.patch
cd orgcopy
patch -p1 < ../from_org_to_revised.patch
you would end up with
├── src
├── orgcopy
| ├── revised
├── revisedcopy
├── revised
--
//Aho
[toc] | [prev] | [next] | [standalone]
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2024-08-05 17:33 +0200 |
| Message-ID | <v8qrch$qt2t$1@dont-email.me> |
| In reply to | #80263 |
> patch -p1 < ../from_org_to_revised.patch The parameter -p1 what is it for?
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2024-08-05 23:05 +0200 |
| Message-ID | <lhct4kFt2soU1@mid.individual.net> |
| In reply to | #80264 |
On 05/08/2024 17.33, alex wrote: > > patch -p1 < ../from_org_to_revised.patch > > The parameter -p1 what is it for? > it's to remove the first level of directory as in my example the paths had been --- orgcopy/orig 2024-08-02 14:22:59.937683379 +0200 +++ revisedcopy/orig 2024-08-02 10:17:25.108469758 +0200 so -p1 would make it same as: --- orig 2024-08-02 14:22:59.937683379 +0200 +++ orig 2024-08-02 10:17:25.108469758 +0200 Say you had had: --- src1/dir/orig 2024-08-02 14:22:59.937683379 +0200 +++ src2/dir/orig 2024-08-02 10:17:25.108469758 +0200 and you are in the src1/dir applying the patch, you would like to remove two levels and use -p2, but if you had been in src1 then you would just use -p1. I hope that was understandable... -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2024-08-06 07:39 +0200 |
| Message-ID | <v8scub$1d5gg$1@dont-email.me> |
| In reply to | #80265 |
Il 05/08/24 23:05, J.O. Aho ha scritto:
>
> it's to remove the first level of directory as in my example the paths
> had been
├── orig
│ └── file.txt
└── revised
└── file.txt
$ cat orig/file.txt
buggated
$ cat revised/file.txt
fixed
$ diff -ur orig/ revised/ > file.patch
├── file.patch (FILE CREATED)
├── orig
│ └── file.txt
└── revised
└── file.txt
$ cd orig/
$ patch < ../file.patch
patching file file.txt
$ cd ..
$ cat orig/file.txt
fixed
To notice
$ patch < ../file.patch
Even if it was not used -p1 it worked equally.
Why?
[toc] | [prev] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2024-08-06 08:06 +0200 |
| Message-ID | <lhdsqiF30ivU1@mid.individual.net> |
| In reply to | #80266 |
On 06/08/2024 07.39, alex wrote: > Il 05/08/24 23:05, J.O. Aho ha scritto: >> >> it's to remove the first level of directory as in my example the paths >> had been > > ├── orig > │ └── file.txt > └── revised > └── file.txt > > $ cat orig/file.txt > buggated > > $ cat revised/file.txt > fixed > > $ diff -ur orig/ revised/ > file.patch > > ├── file.patch (FILE CREATED) > ├── orig > │ └── file.txt > └── revised > └── file.txt > > $ cd orig/ > > $ patch < ../file.patch > patching file file.txt > > $ cd .. > > $ cat orig/file.txt > fixed > > To notice > > $ patch < ../file.patch > > Even if it was not used -p1 it worked equally. > > Why? I guess for you have the original path setup, I tend to prefer to use the -p option no matter what. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Date | 2024-08-06 07:36 +0200 |
| Message-ID | <v8t8u7$1k2m4$1@dont-email.me> |
| In reply to | #80265 |
Il 05/08/24 23:05, J.O. Aho ha scritto:
>
> it's to remove the first level of directory as in my example the paths
> had been
├── orig
│ └── file.txt
└── revised
└── file.txt
$ cat orig/file.txt
buggated
$ cat revised/file.txt
fixed
$ diff -ur orig/ revised/ > file.patch
├── file.patch (FILE CREATED)
├── orig
│ └── file.txt
└── revised
└── file.txt
$ cd orig/
$ patch < ../file.patch
patching file file.txt
$ cd ..
$ cat orig/file.txt
fixed
To notice
$ patch < ../file.patch
Even if it was not used -p1 it worked equally.
Why?
[toc] | [prev] | [standalone]
Back to top | Article view | alt.os.linux
csiph-web