4.4 Editing Files
Now that you have checked out a working copy of the repository, it's time to edit some files. Let's say, for example, that you decide that your Hello World program needs to tell everyone about a glorious new system that you've just discovered. So, you bring up your favorite text editor and modify hello.c, so that it now looks like this:
#include <stdio.h> int main(int argc, char** argv) { printf("Subversion Rocks!!\n); return 0; }
Whew! After a big change like that, it can be hard to remember everything that you've done since the repository was checked out. Sounds like it's time to learn about Subversion's query commands. [2]
Subversion provides you with a couple of different commands for querying the current state of the working directory. The first, svn status, shows the current status of local files. You can see whether files have been added, modified, deleted, and a number of other things. Running it on your current working directory shows that one file has changed:
$ svn status my_repos_trunk M my_repos_trunk/hello.c
Each output line from SVN (in this case, only one) shows the state of a file in the working directory tree, with files that haven't changed since the last update omitted. As you can see, the hello.c file is listed, with an M that informs you that the local file has been modified.
Just knowing that the file has been modified, though, doesn't tell you a whole lot. It would be significantly more useful if you could see exactly what has been modified. This is where the svn diff command comes in. With the diff command, you can see the difference between the local copy of the file and the last version to be updated from the repository (you can also use the diff command to compare with revisions other than the most recent, as you'll see in Chapter 5, "Working with a Working Copy").
$ svn diff my_repos_trunk/hello.c Index: my_repos_trunk/hello.c ================================================================ --- my_repos_trunk/hello.c (revision 1) +++ my_repos_trunk/hello.c (working copy) @@ -2,7 +2,7 @@ int main(int argc, char** argv) { - printf("Hello World!!\n"); + printf("Subversion Rocks!!\n"); return 0; }
As you can see, the diff command gives you an overview of the changes made to the file, including both removed information and added information. The header portion of the output identifies which files have been diffed. In this case, it shows that the original file was revision 1 of hello.c, and all lines from that which have been removed in the latest version (which it notes, is the working copy) are marked with a - sign. Additionally, all lines added to the working copy, but not in revision 1, are marked with a +. The @@ -2,7 +2,7 @@ tells you that the diff to follow shows lines two through seven from both versions of hello.c. For each section of a file that has changed, the diff will show the changes, as well as a few of the unchanged lines before and after the change. These can help you get your bearings as to which section of the file it is that you are seeing changed.