当我们想在原文件和新文件之间生成patch,并用这个patch文件,应用在原文件上快速完成更新时,可以使用以下步骤:
- 用diff生成patch
$ echo "12345\ntesting"> old_file $ echo "125testing\ntesting1234"> new_file $ # We have 2 common ways to get the patch $ # The first way is : $ diff old_file new_file > file_patch $ # We can see the patch are generated by lines $ cat file_patch 1c1 < 12345\ntesting --- > 125testing\ntesting1234 $ # The second way is : $ diff -c old_file new_file > c_file_patch $ # Then we can see the patch are generated by contents $ cat c_file_patch *** old_file 2018-12-27 21:06:57.922518425 +0800 --- new_file 2018-12-27 21:07:11.551401751 +0800 *************** *** 1 *** ! 12345\ntesting --- 1 ---- ! 125testing\ntesting1234 $ # We also can get one whole patch for files of the whole directories $ mkdir -p new_dir old_dir $ echo "123" > new_dir/test_1.txt $ echo "789testing" &g