官术网_书友最值得收藏!

Creating a diff of two files and patching

In what case should you know what a diff is? Or a patch? In the Linux world, it is a way to determine the differences between files and also to solve problems at the OS level (especially if you have a broken driver in the Linux kernel). However, for the purposes of a cookbook, diffs and patches useful for a couple of main things:

  • When determining whether a particular script or configuration file has modifications
  • When plotting differences between versions, or migrating data between an old to new script, and so on

So, what is a diff or differential? A diff is the output that describes the differences between two files (file A and file B). The file A is the source, and the B file is the assumed to be modified file. If no diff output is created, then A and B are either empty or there are no differences. Diffs in a unified format typically look like this:

$ diff -urN fileA.txt fileB.txt 
--- fileA.txt 2017-12-11 15:06:49.972849620 -0500
+++ fileB.txt 2017-12-11 15:08:09.201177398 -0500
@@ -1,3 +1,4 @@
12345
-abcdef
+abcZZZ
+789aaa

There are several formats of diffs, but the unified format is among the most popular (and used by the FOSS crowd). It contains information about both files (A and B), the line numbers and counts in each, and the content added or changed. If we look at the preceding sample, we can see that in the original, the string abcdef is removed (-) and then re-added (+) as abcdZZZ. And there is the further addition of a new line containing 789aaa (which can also be seen here: @@ -1,3 +1,4 @@).

A patch is a unified diff that contains changes to one or more files that are to be applied in a specific order or method, hence the concept of patching being the process of applying a patch (which contains diff information). A patch can consist of several diffs concatenated together as well.

主站蜘蛛池模板: 绥化市| 柞水县| 波密县| 彰化市| 贺州市| 盱眙县| 台南市| 德化县| 子洲县| 涿州市| 利辛县| 长宁区| 吉木乃县| 鱼台县| 绥江县| 靖边县| 托克逊县| 山阴县| 秦皇岛市| 竹山县| 响水县| 满城县| 长沙市| 射阳县| 江安县| 荣昌县| 来宾市| 苏尼特左旗| 石河子市| 石家庄市| 城步| 阿图什市| 南昌市| 大港区| 镇赉县| 崇仁县| 泾源县| 彰武县| 建始县| 玛多县| 龙川县|