Дерево каталогов Diff и patch - PullRequest
0 голосов
/ 12 марта 2020

Для настройки тестовой среды я делаю следующее:

$ mkdir test_orig/ && echo "This is a test" > test_orig/testfile
$ mkdir test_dest/ && echo -e "This is a test.\nThis is a change." > test_dest/testfile
$ echo "This is a newfile" > test_dest/newfile

Моя цель - создать патч с изменениями между test_orig / и test_dest /, а затем применить к test_orig /, чтобы он имел то же самое содержимое как test_dest /. Я следую инструкциям на https://www.thegeekstuff.com/2014/12/patch-command-examples/ (см. Раздел 3), я перечитал некоторые другие ресурсы, такой же подход во всех них.

Итак, я делаю:

$ diff -Naru test_orig/ test_dest/ > test.patch

Patchfile содержимое:

diff -Naru test_orig/newfile test_dest/newfile
--- test_orig/newfile   1970-01-01 01:00:00.000000000 +0100
+++ test_dest/newfile   2020-03-12 12:54:02.575105100 +0100
@@ -0,0 +1 @@
+This is a newfile
diff -Naru test_orig/testfile test_dest/testfile
--- test_orig/testfile  2020-03-12 12:54:02.553052100 +0100
+++ test_dest/testfile  2020-03-12 12:54:02.571104000 +0100
@@ -1 +1,2 @@
-This is a test
+This is a test.
+This is a change.

И я применяю с:

$ patch -p0 < test.patch
The next patch would create the file test_dest/newfile
...

Так что это не работает! Если я сделаю патч в противоположном направлении:

$ diff -Naru test_dest/ test_orig/ > test.patch
$ patch -p0 < test.patch

Затем test_dest / заканчивается с тем же содержимым, что и test_orig /, как и ожидалось.

Что здесь не так?

...