- Bash Cookbook
- Ron Brash Ganesh Naik
- 333字
- 2021-07-23 19:17:42
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.
- 構建移動網站與APP:HTML 5移動開發入門與實戰(跨平臺移動開發叢書)
- Unity Shader入門精要
- MATLAB 2020從入門到精通
- Asynchronous Android Programming(Second Edition)
- Mastering ROS for Robotics Programming
- Android Wear Projects
- TMS320LF240x芯片原理、設計及應用
- JavaScript程序設計(第2版)
- 軟件項目管理實用教程
- Maker基地嘉年華:玩轉樂動魔盒學Scratch
- C語言程序設計實訓教程與水平考試指導
- SQL Server 2008中文版項目教程(第3版)
- Solr權威指南(下卷)
- 快樂編程:青少年思維訓練
- Drupal 8 Module Development