Create a Repository
To store projects in Subversion, first you must create a repository. This must be done to a local drive on a local machine. Creating a repository on a network drive is not supported. To create a repository type:
UNIX: svnadmin create /path/to/repository
Windows: svnadmin create d:/path_to_repository
By default this sets up a Berkeley database to store the repository. Individual projects should be created as subdirectories of the repository directory (the forward slashes are required even on Windows)
Add a New Project - svn import
To add a project, the Subversion documentation suggests that you create a directory structure like the following:
A root project directory contains three subdirectories, branches, tags, and trunk. Your files and directories are stored under the trunk directory.
Create the directories as described. Assuming the project directory is a subdirectory of the current directory, you would enter the following command
UNIX: svn import project file:///repository_name/project -m "First Import"
Windows: svn import project file:///d:/repository_name/project -m "First Import"
Network: svn import project http://host_name/svn_dir/repository_name/project -m "First Import"
Commonly Used Commands
1.) Checkout the code
$svn checkout http://192.168.0.54/svn/repos/server_code server_code
If your repository requires authentication:
$svn checkout –username my_username http://192.168.0.54/svn/repos/server_code server_code
Update your working copy:
$svn update
(update from current)
$svn update -r BASE server_code
(update foo from base revision)
$svn update -r 1200 server_code (update foo from revision number 1200)
2.) Make changes:
$svn add eg svn add new_directory
(add a new directory foo)
$svn delete
$svn copy directory1 directory2
(copy directory directory1 to directory2)
$svn move directory2 renamed_directory
(rename?)
3.) Examine your changes (Can be done even with no network access to the subversion repository):
$svn status (To get an overview of all your changes)
$svn diff (to show changes between current working directory and the same directory in the repository)
4.) Possibly undo some changes
$svn revert
After running svn revert as a way to resolve local conflict with the repository copy, Run:
$svn resolve
To inform svn that the conflict has been resolved. You will now be able to successfully run svn update in case of previous conflicts.
5.) Resolve Conflicts (Merge Others’ Changes):
$svn update
$svn resolved
6.) Commit your changes:
$svn commit
eg
$svn commit -m “Removed out of mem errors.”
or
$svn commit -F comment.txt
or
$svn commit –file comment.txt
6. Logs:
$svn log (use current working directory as the default target)
$svn log server_code
(current working directory/file is server_code)
$svn log -r 5:19
(shows logs 5 through 19 in chronological order of working directory)
$svn log -r 19:5
(shows logs 5 through 19 in reverse order of working directory)
$svn log -r 8
(shows log for revision 8 of working directory)
$svn log -r 8 -v
(shows verbose? log for revision 8 of working directory)
7. Diffs (Changes):
$svn diff
$svn diff -r 3 rules.txt
(or svn diff –revision 3 rules.txt)
$svn diff -r 2:3 rules.txt
(revisions 2 and 3 are directly compared)
$svn diff -c 3 rules.txt
(compare changes between current revision and revision 2)
8. Browse a file directly:
svn cat -r 2 rules.txt
svn cat -r 2 rules.txt > rules.txt.v2 (send cat output directly to a file)
9. Browse a folder directly:
svn list http://svn.collab.net/repos/svn
svn list -v http://svn.collab.net/repos/svn
10. Fetching older repository snapshots:
$svn checkout -r 1729
(Checks out a new working copy at r1729)
$svn update -r 1729
(Updates an existing working copy to r1729)
11. Checkout based on revisions:
$svn checkout -r {2006-02-17}
$svn checkout -r {15:30}
$svn checkout -r {15:30:00.200000}
$svn checkout -r {“2006-02-17 15:30″}
$svn checkout -r {“2006-02-17 15:30 +0230″}
$svn checkout -r {2006-02-17T15:30}
$svn checkout -r {2006-02-17T15:30Z}
$svn checkout -r {2006-02-17T15:30-04:00}
$svn checkout -r {20060217T1530}
$svn checkout -r {20060217T1530Z}
$svn checkout -r {20060217T1530-0500}
12. Logs based on revisions:
$svn log -r {2006-11-28}
$svn log -r {2006-11-20}:{2006-11-29}
13. Locking files:
$svn lock banana.jpg -m “Editing file for tomorrow’s release.”
‘banana.jpg’ locked by user ‘harry’.
14. Creating branches:
$svn checkout http://svn.example.com/repos/calc bigwc
A bigwc/trunk/
A bigwc/trunk/Makefile
A bigwc/trunk/integer.c
A bigwc/trunk/button.c
A bigwc/branches/
Checked out revision 340.
Now create the branch;
$cd bigwc
$svn copy trunk branches/my-calc-branch
$svn status
A + branches/my-calc-branch
$svn commit -m “Creating a private branch of /calc/trunk.”
Adding branches/my-calc-branch
Committed revision 341.