- 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.
- C++案例趣學(xué)
- JavaScript前端開發(fā)模塊化教程
- Mastering AWS Lambda
- PHP 從入門到項(xiàng)目實(shí)踐(超值版)
- Java高手真經(jīng)(高級編程卷):Java Web高級開發(fā)技術(shù)
- 青少年軟件編程基礎(chǔ)與實(shí)戰(zhàn)(圖形化編程三級)
- Magento 2 Theme Design(Second Edition)
- 云原生Spring實(shí)戰(zhàn)
- 深入理解Elasticsearch(原書第3版)
- NetBeans IDE 8 Cookbook
- Python機(jī)器學(xué)習(xí)算法與應(yīng)用
- Java Web從入門到精通(第3版)
- Illustrator CS6設(shè)計(jì)與應(yīng)用任務(wù)教程
- Visual Basic語言程序設(shè)計(jì)基礎(chǔ)(第3版)
- Python預(yù)測分析與機(jī)器學(xué)習(xí)