With Subversion now installed, you are ready to start using the commands to work with a repository.
Create a working copy from the repository in the local directory. You can checkout just a subdirectory of the repository if you only want a single project or branch.
svn checkout http://svn.example.com/projects/project1 myproject Checks out the "project1" subdirectory from the repository at http://svn.example.com/projects to a new directory called "myproject" within the current directory.
Bring new changes from the repository into the working copy in this directory. The command needs no arguments; it picks up all the information it needs from the metadata in the current directory.
If you see conflicts when you update, look at the svn resolve command for help.
Check the current status of your working copy, showing any files that are modified, new, or have other special statuses. You can run svn status from a subdirectory to only see changes in that directory and below it.
The list does not show files that are in sync with the repository, as there's no special information about those. The list shows a code in the left hand column, which denotes the status. The codes are:
Added - This new file will be included with the next commit.
Conflicted - This file has local and remote changes which affect the same line.
Deleted - This file will be deleted on the next commit.
Modified - This file has been changed, and the changes will be included in the next commit.
This file is not under version control (you can add it now, if you like)
||This file is missing. To reinstate it, run svn update. To delete files safely, use svn rm. If this file shouldn't be under source control, consider setting an ignore on it (see the “Properties” section).
Represents an external resource managed by svn (svn:externals).
Running svn status is strongly recommended before updating or committing files.
Bring a new file under source control. When you create a new file and then run svn status—the file will show with a "?". To add a file called script1.php to your project so that it will be committed, use svn add:
svn add script1.php
Next time you commit to the repository, this file will be included.
Removes the local, uncommitted changes to this file. The revert will change the file to the newest version that came from the repository.
svn revert script1.php
Sends local changes to the repository, usually after completing a bug fix or task. Any files shown as M or A by svn status will be sent to the repository. You will be prompted to include a commit message to say what you changed and why, or you can specify this on the command line with the -m switch.
svn commit -m "commit all my files"
When you commit from a subdirectory only the changes in the current directory and below will be included.
svn commit -m "commit only changes in the images directory"
To include only specific files, list those files at the end of your command.
svn commit -m "commit only the CSS file" style.css
It is recommended to run two commands before you commit:
- svn update to synchronize with the central repository. If any of your changes conflict with changes made to the repository, you will resolve these before you commit.
- svn status to check which changes will be sent.
This command enables you to handle conflicts. Conflicts occur when there are multiple changes to the same line number in a file; Subversion doesn't know what to do about that and will ask you to resolve the conflict yourself. Conflicts occur when you run svn update from the main repository, or when you commit if you didn't update first.
Many clients will offer you the opportunity to resolve the conflict interactively. You will see which lines were changed locally and which were changed on the repository—you can then either pick which version should be used or edit the file as appropriate. When handling source code, many conflicts occur because two developers have added new functions to the end of the same library file – and Subversion just sees that the same lines have been changed. If you resolve interactively, then all is well. If not, you will need the svn resolve command.
When a file is conflicted, it will show the C label in svn status. It is not possible to commit from this repository until the conflict is resolved. When you have a conflict, some extra files appear in your working copy. These have extensions showing which revision they are from, and they are:
- .mine is the local version of your file from before the conflict.
- .rX (where X is a revision number) are the committed revisions from the repo. One will be the version your changes were based on, and the newer one is the current version in the repository.
The actual file with the conflict will have notation in the file showing which version is in which revision, and it will look something like this:
$greeting = 'hello world';
$message = 'hello world';
Either copy one of the "extra" files over the original, or edit the file with the conflicts in until it looks right. Make sure you remove all the ASCII art notation from the file! Once you are ready, you can tell Subversion that you have dealt with the conflict:
svn resolve script1.php
The extra files will then be deleted, and the svn status command will show M rather than C for this file. Once done, you can commit your changes.