How to recursively create a patch file using diff

I am working on Linux, working on creating a PHP project. I want to create a patch file that I made that can be applied to the last parent code. Both the source folder and the new code folder are many subdirectories in depth (so you need a recursive one).

For some reason, when I do this:

diff -ur folder1 folder2 > newcode.patch 

I am unable to get the patch file, including all new files, and it does not even contain some deeper file changes (at about 3+ levels).

Any ideas how to do this? I looked at Meld and Kdiff3 ... but they don't seem to do what I want.

+4
source share
3 answers

I suspect you have a directory structure, something like:

 folder1/ text.txt level1/ text1.txt level2/ text2.txt level3/ text3.txt folder2 text.txt level1/ text1.txt level2/ text2.txt anewdirectory/ newtext.txt level3/ text3.txt newfiled3.txt 

In this case, diff will ignore the newtext.txt file inside anewdirectory/ . It probably also does not display the text newfiled3.txt . Instead, it reports something like:

 .. Only in folder2/level1/level2/ : anewdirectory Only in folder2/level1/level2/level3/ : newfiled3.txt .. 

Is this a symptom that you see?
Try:

 diff -urBNs folder1/ folder2/ > code.patch 
+9
source

If diff -r does not work as described on the man page, it is clearly broken; however, I would create a local version control repository using the source code, and then, once you have done that, commit the new code. Any version control system worthy of its salt will be able to create a patch between the faithful versions.

+1
source

I assume the source project is under some version control. If so, good tools should be created for this version control system that will allow you to create the patch. For example, if the source control system is Subversion (SVN) and you are on Windows, you can use TortoiseSVN to create this patch.

Do not reinvent the wheel.

0
source

Source: https://habr.com/ru/post/1388772/


All Articles