パッチ

シナリオ

ファイル test_old, test_new を用意し、そのパッチファイル(差分) test.patch を作成。
patch コマンドを使って、test_old を test_new と同じ内容に変更。
再び patch コマンドを使い、元の test_old に戻す。
必要に応じ patch パッケージをインストールしておく。

サンプルファイル

今回用いたファイルは以下の通り。
test_oldtest_new
YES(1)			      User Commands			  YES(1)

NAME
       yes - output a string repeatedly until killed

SYNOPSIS
       yes OPTION

DESCRIPTION
	Repeatedly output a line with all specified 'y'.
  
YES(1)			      User Commands			  YES(1)

NAME
       yes - output a string repeatedly until killed

SYNOPSIS
       yes [STRING]...
       yes OPTION

DESCRIPTION
	Repeatedly output a line with all specified STRING(s), or 'y'.
  

パッチ適用

パッチを使って、test_old を test_new 変更
$ diff test_old test_new
1,2d0
< test_old	test_new
< 
8a7
>        yes [STRING]...
12c11
< 	Repeatedly output a line with all specified 'y'.
---
> 	Repeatedly output a line with all specified STRING(s), or 'y'.

$ patch -p1 < test.patch
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- test_old	2021-01-17 23:26:15.186784732 +0900
|+++ test_new	2021-01-17 23:25:45.740184222 +0900
--------------------------
File to patch: test_old
patching file test_old

$ head test_old
YES(1)			      User Commands			  YES(1)

NAME
       yes - output a string repeatedly until killed

SYNOPSIS
       yes [STRING]...
       yes OPTION

DESCRIPTION
変更を元に戻す。
$ patch -R < test.patch
patching file test_old

$ head test_old
YES(1)			      User Commands			  YES(1)

NAME
       yes - output a string repeatedly until killed

SYNOPSIS
       yes OPTION

DESCRIPTION

パッチファイル

パッチファイルは diff コマンドで生成できる。
$ diff -u test_old test_new > test.patch

$ cat test.patch
--- test_old	2021-01-17 23:26:15.186784732 +0900
+++ test_new	2021-01-17 23:25:45.740184222 +0900
@@ -4,10 +4,11 @@
	yes - output a string repeatedly until killed

 SYNOPSIS
+	yes [STRING]...
	yes OPTION

 DESCRIPTION
-	Repeatedly output a line with all specified 'y'.
+	Repeatedly output a line with all specified STRING(s), or 'y'.