Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

diff - How to create a patch for a whole directory to update it?

I know there are several threads on this already, but no one has fully explained exactly how to perform the initial diff to create the patch file, then how to apply that patch to the initial directory to update it.

In my case, there is a directory of files that anyone can download from the web. I have taken that directory and made changes to it, and want to create a patch file such that others can apply it to the downloaded directory to reproduce exactly what I have in my modified directory.

Help? What do I need to tell the other person with respect to how to apply my patch?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just had this same problem - lots of advice on how to half do it. Well, here is what I did to get both the patching and unpatching to work:

To Create the Patch File:

  1. Put copies of both directories in say /tmp, so we can create the patch file, or if brave, get them side by side - in one directory.

  2. Run an appropriate diff on the two directories, old and new:

    diff -ruN orig/ new/ > file.patch
    # -r == recursive, so do subdirectories
    # -u == unified style, if your system lacks it or if recipient
    #       may not have it, use "-c"
    # -N == treat absent files as empty
    

If a person has the orig/ directory, they can recreate the new one by running patch.

To Recreate the new folder from old folder and patch file:

  1. Move the patch file to a directory where the orig/ folder exists

  2. This folder will get clobbered, so keep a backup of it somewhere, or use a copy.

    patch -s -p0 < file.patch
    # -s == silent except errors
    # -p0 == needed to find the proper folder
    
  3. At this point, the orig/ folder contains the new/ content, but still has its old name, so:

    mv orig/ new/    # if the folder names are different
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...