$diff hello.c hello.c.punct
8c8
< printf("Hello, World!\n");
---
> printf("Hello, World.\n");
$diff -u hello.c hello.c.punct
--- hello.c 2011-02-22 14:18:15.000000000 -0500
+++ hello.c.punct 2011-02-22 14:18:08.000000000 -0500
@@ -5,6 +5,6 @@
The first format, without the -u option has in its output's first line "8c8", where the 'c' between the numbers indicates that changes were made, and first number '8' means line 8 in the original file (hello.c) was replaced with line 8 (second number '8') in the modified file (hello.c.punct).
The -u option in the second format specifies to use the unified diff format for the output.
--- and - indicate the original file. +++ and + indicate the modified file.
The double-at signs indicate where changes were made in the modified file. The first number between these signs is the starting line of the actual code (excluding comments), and the second number shows how big the modified "hunk" is. Here, it is 6 lines of code starting at line 5.
7.8. Exercise - Create a Patch for a New File
The file foo needs to be created using the contents of an existing file bar. We can compare the contents of bar with an empty file (/dev/null on ubuntu) by using diff with the unified format and output the results to bar.patch. Then we can apply the patch and specify a file foo, which then creates the new file foo with the contents of the original bar file.
diff -u /dev/null bar > bar.patch
patch foo < bar.patch
Interesting.
7.9. Exercise - Patch echo
This part took longer than I thought it would (gotta love compiling). But then I had to figure out what the patched code was actually supposed to be doing. And then I realized they changed one of the parameters in their modified code. Oops. (Recompile.)
Now it works. Anything entered after src/echo and separated by a space comes back in reverse order, just like the exercise describes.
No comments:
Post a Comment