iDog's Guide of Subversion Usage
iDog
Download and install
Download subversion at its official website:
http://subversion.tigris.org/
You'd better download its source code and then build it in your local machine. It's pretty straightforward, so omitted here.
Create repository
mkdir -p /var/svn/myrepo
svnadmin create /var/svn/myrepo
Then configure the repository:
Open file /var/svn/myrepo/conf/svnserve.conf, uncomment the line starting with 'password-db':
# [general]
# password-db = passwd
Open file /var/svn/myrepo/conf/passwd, add accounts under '#[users]':
# [users]
idog = idog123
icat = icat456
Start svn daemon
svnserve --daemon --root /var/svn/myrepo
Import existing project
Suppose that we have a project in following dir:
/home/idog/myproj
Then do following commands to add it to repository:
svn mkdir svn://localhost/myproj
cd /home/idog/myproj
svn import . svn://localhost/myproj
svn commit
If you have an extra file/dir to add, then
svn add <file_or_dir_name>
svn commit
Add new files
svn add path/to/files
# add dir and all dirs/files under it
svn add my_dir
# only add dir
svn add --depth empty my_dir
Check in & check out code
svn co svn://localhost/myproj
# some modifications on files...
svn ci
Ignore some files
# ignore all *.log files in log dir
svn propset svn:ignore *.log ./log/
Revisions
1. Revision number: an integer
2. Revision Keywords
- HEAD: latest revision
- BASE: base of your working copy (without your modifications)
- COMMITTED: last revision before or at BASE.
- PREV: COMMITTED - 1
3. Revision Dates: svn finds the latest revision till this time.
{yyyy-mm-dd}
{yyyymmdd}
{hh:mm}
{hh:mm:ss.xxxxxx}
{"yyyy-mm-dd hh:mm"} # use "" since there is a space
{yyyymmddThhmm}
{yyyy-mm-ddThh:mm}
when time is not specified, svn assumes 00:00:00.
svn log -r {yyyymmdd}:{YYYYMMDD} #specify a range to log
svn diff -r {yyyymmdd}:nnnn # compare two versions
Basic work cycle
update working copy
svn update
Result in following format:
F filename
Flag 'F' meanings:
U updated
A added
D deleted
R replaced (deleted a file but added another with the same name)
G merged successfully
C merged with conflicts. need to be resolved manually.
Make changes to working copy
work on files, and use following commands:
svn add <filename>
svn delete <filename>
svn copy <file1> <file2>
svn move <file1> <file2>
Examine local changes
svn update
Result is as follows:
F filename
Flag 'F' meanings:
A scheduled addition
C in state of conflict
D scheduled deletion
L locked
M modified
X unversioned but is an external definition
? not under version control
! under version control but missing or incomplete
~ type mismatch (e.g.: versioned as dir, but is file)
I unversioned, and svn is configured to ignore it
svn diff
svn diff > patch.txt
svn revert
revert: overwrite working copy with BASE, or cancel scheduled task (e.g.: cancel a deletion).
Resolve conflicts
- do 'svn update', then modify all files flagged as 'C'.
- modify conflicted files
- run 'svn resolved <file>'
- commit
When there is a conflict, 3 extra files are created:
- <filename>.mine: working copy before doing update
- <filename>.r<mmm>: BASE revision
- <filename>.r<nnn>: file received from svn server when updating
Examine history
svn log
svn diff
svn cat # retrieve file of a revision and print it to screen
svn list # list files in a dir of a revision
Other commands
svn cleanup # clean up any unnecessary logs, remove locks
svn import # copy unversioned dir into repository.
svnadmin create /usr/lcoal/svn/my_repo
svn import mydir file:///usr/local/svn/my_repo/myproject
After import operation, this dir is not converted into a working copy.
Branches, Tags and Merges
In svn, branches and tags are simply copies.
svn mkdir svn://localhost/branches
svn copy svn://localhost/myproj svn://localhost/branches/myproj/1.0
If modifications are made in branch, we can use merge command to merge them back to main trunk:
svn merge -r nnn:HEAD svn://localhost/branches/myproj/1.0 .
Note that the 'nnn' means the base of the branch. For example, project started from r240, made the branch at r242, branch's top is r243, trunk's top is r244, then the command is:
(240)---(241)---(242)---(244)---(245)---------
| (branch) | (merge)
(242)---(243)-----+
svn merge -r 242:HEAD svn://localhost/branches/myproj/1.0 .