home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.os.linux      Getting to be as bloated as Windows!      107,822 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 106,354 of 107,822   
   J.O. Aho to alex   
   Re: patch a file with the patch command   
   05 Aug 24 12:43:14   
   
   From: user@example.net   
      
   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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca