- 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.
- ASP.NET Core 5.0開發入門與實戰
- Xcode 7 Essentials(Second Edition)
- Vue.js 3.x從入門到精通(視頻教學版)
- Learning RabbitMQ
- 青少年軟件編程基礎與實戰(圖形化編程三級)
- Python Tools for Visual Studio
- 基于差分進化的優化方法及應用
- Python數據分析(第2版)
- Kinect for Windows SDK Programming Guide
- Functional Kotlin
- Practical Predictive Analytics
- 人人都能開發RPA機器人:UiPath從入門到實戰
- Java程序設計實用教程(第2版)
- Visual Basic語言程序設計上機指導與練習(第3版)
- Mastering Machine Learning with R