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

File modifications

When you should modify a text file, I'm going to use the unified context diff format since this is a very efficient and compact way to represent a text modification. This format can be obtained by using the diff command with the -u option argument, or by using the git diff command within a git repository.

As a simple example, let's consider the following text in file1.old :

This is first line
This is the second line
This is the third line
...
...
This is the last line

Suppose we have to modify the third line, as highlighted in the following snippet:

This is first line
This is the second line
This is the new third line modified by me
...
...
This is the last line

You can easily understand that reporting the whole file  each time for a simple modification is unnecessary and space-consuming; however, by using the unified context diff format, the preceding modification can be written as follows:

$ diff -u file1.old file1.new
--- file1.old 2019-05-18 14:49:04.354377460 +0100
+++ file1.new 2019-05-18 14:51:57.450373836 +0100
@@ -1,6 +1,6 @@
This is first line
This is the second line
-This is the third line
+This is the new third line modified by me
...
...
This is the last line

Now, the modification is very clear and written in a compact form! It starts with a two-line header, where the original file is preceded by --- and the new file is preceded by +++. Then, it follows one or more change hunks that contain the line differences in the file. The preceding example has just one hunk where the unchanged lines are preceded by a space character, while the lines to be added are preceded by a + character and the lines to be removed are preceded by a - character.

Nonetheless, for space reasons, most patches reproduced in this book have reduced indentation in order to fit the width of printed pages; however, they are still perfectly readable. For the full patch, you should refer to the provided files on GitHub or the Packt site.

主站蜘蛛池模板: 浪卡子县| 班玛县| 瓮安县| 大冶市| 凤庆县| 秭归县| 兰西县| 马边| 永修县| 马公市| 乐至县| 团风县| 图们市| 庆安县| 启东市| 泸州市| 上犹县| 永修县| 安泽县| 裕民县| 济南市| 景宁| 宜良县| 蓝田县| 明溪县| 阿拉善左旗| 万载县| 公安县| 青铜峡市| 澄城县| 桦川县| 财经| 乃东县| 淮北市| 邵东县| 大名县| 嘉峪关市| 潼南县| 莱阳市| 游戏| 方山县|