Join Michael Lehman for an in-depth discussion in this video Working with check-in, checkout, and revert, part of Learning Software Version Control.
We've got a repository and a project set up. Let's add a file and check it in. Our working set is in the trunk directory, so first we change to that directory and then we'll create the file and we're going to put in the following code. The content is from the new project haiku error messages page. We're going to pick one that's happened to all of us before we started using Version Control. With searching comes loss and the presence of absence, My Novel not found. All right.
So we save it, and now we're going to add it to the repository. But before we add it to the repository, let's ask Subversion what's the status of the files in this directory. You can see it doesn't know what to do with f1.c because we have to tell it to add it to the repository. So to add it, we type svn add f1.c, and then if we run svn status again, you can see we have a pending add for our file that's not yet been checked in. So to check it in, we're going to commit it, we're going to type svn commit, and we're going to put a commit message on the command line here, Add f1.c.
Now, if we ask svn the status of this project, we can see that all the files are checked in. But if we want to look at the log, we can only see the message that says, we imported the structure. You might wonder what happened to my check in? Well, with svn, in order to get the log up to date, you need to run svn update command. Now when we look at the log, you can see both the initial creation of the directory and the addition of f1.c. Now, if you look at the beginning of each of the lines in the log, here, and here, you can see the letter R followed by a number.
In Subversion, this is the revision number or changeset ID. So let's use Notepad to open up f1.c, and then we'll change the words "My Novel" to the word "Website". Now we'll save the file. Now we're going to check it in again, but this time we'll use the editor feature to add our commit message. SVN has many shortcuts for its commands, and in this case we'll use svn ci, which is a shortcut for commit. As you saw before, CO is used for check-out, so they had to use some other set of letters, instead of using CO for commit, they used CI, as in check in.
So we type this and Notepad opens. You did remember to set your SVN_EDITOR environment variable right? If not, you got an error message at this point. So set that environment variable now and rerun this command in order to follow along from this state. So in the editor that appears, in our case it was Notepad, you might have set it up to use your own favorite editor. We're going to add a multi-line message, so Change "My Novel" to Website.
Change message to better reflect product features. And as we save this and exit, we can once again run svn update, and then run svn log and see here's our Import structure, our Add f1.c, and our multi-line change message. Now, when you're trying to hunt for A revision number for some of the commands we're about to use, this could get very, very long with all of the change messages.
So the log file command has a way of allowing you to see just the revision numbers and the times. So if you type svn log -q, you get a listing that just has one line for each revision or changeset that's been checked in. So now let's make another change, and then we'll roll it back. So once again, we're going to open up f1.c, and we're going to change Website to Webpage. In order to see the differences between our most recent version in our working set, we can use the svn diff command, and you can see it shows that we're currently on revision 4 in the repository. This is our working copy, and here this is essentially the line we deleted, website not found, and this is the line we added or essentially changed to Web page not found.
Now, svn diff shows the differences between all the files in the working set and the repository. So if we want to only see the differences between one file in the current repository, we can say svn diff f1.c. Now in our case, it's going to be exactly the same, because we only have one file. You can also ask for the differences between the working set and a specific version. So for example, if we say svn diff and ask for the distance between this and revision 3, you can see that in revision 3 we had "My Novel" and currently we have Webpage. All right.
Now, let's roll back to the topmost revision, which is our most recent commit. So we say svn revert and revert this file. Now it's reverted. Now when we type it out, you can see we're back to Website. Finally, you can also revert to any revision, not just the top revision by using the update command. So let's go svn update, back to revision 3, and when we type it out again, we're back to "My Novel".
Note, none of your changes in the repository have been lost. Everything is all still there. It's just the basic workflow of being able to update the working set. So for example, we could update back to revision 4 and get back to Website, and now we're back to Website. Remember, none of your changes in the repository have been lost. You're just updating your working set. So that's the basic workflow of check in, check out, and revert. You'll also want to look at the Subversion documentation to see how to delete files, how to rename files, and how to move files within directories and create other directories.
All right. Now, let's move on to tagging.
- Comparing centralized vs. distributed systems
- Saving changes and tracking history
- Using revert or rollback
- Working with the GUI tools
- Using IDE and shell integration
- Installing different systems
- Creating a repository
- Tagging code
- Branching and merging code
- Selecting a software version control system that's right for you