Getting started with SVN in less than five pages Contents

advertisement
Getting started with SVN in less than five pages
Theory Lab, School of Computing, University of Utah
September 14, 2010
Contents
1 Points to be noted:
2
2 Server Setup:
2.1 How to create a repository? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 How to add your project to the repository? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
2
2
3 Client Access:
3.1 How to checkout from repository? . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 How to commit your modifications/changes to the repository? . . . . . . . . .
3.3 How to add/delete new files/folders to/from repos? . . . . . . . . . . . . . . . .
3.4 How to update your version to the latest version available in the repository?
3.5 How to list contents in the repository? . . . . . . . . . . . . . . . . . . . . . . .
3.6 How to change project name? . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
2
3
3
3
3
3
3
4 Miscellaneous:
4.1 How to send post-commit mails? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
4
5 SVN Backup:
4
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1
Points to be noted:
• The following commands will get you started for SVN. For complete and exhaustive documentation refer the online manual at http://svnbook.red-bean.com
• For illustrative examples, in the following we assume a project named bnn (which contains
the files bnn.tex, bnn.bib, bnn.pdf) and a svn repository directory named svn located at /uusoc/res/algo/. All the following example commands (in bold face blue font) have been tested
and work fine.
• The tutorial has been written assuming that the reader is affiliated to the School of Computing (SoC) with a valid and working UNIX account. If otherwise, kindly modify the “paths”
accordingly. Some cases will work only with a valid SoC account.
• Send corrections, updates, modifications or any other comments to avishek@cs.utah.edu
2
Server Setup:
These operations need to be performed only once for setting up the repository and adding your project folder
to it. If a SVN repository already exists then you need create the repository and can skip to Section 2.2.
2.1
How to create a repository?
svnadmin is the command to create the repository. Its usage is shown below:
$ svnadmin create /path/to/repos --fs-type fsfs
$ svnadmin create svn –fs-type fsfs
Note: The option - -fs-type fsfs is really optional. But it is necessary if you want to maintain your repository
on a network file system. In a network file system, data corruption might occur without this option.
2.2
How to add your project to the repository?
Create the project tree structure as shown below:
/tmp/bnn/branches/
/tmp/bnn/tags/
/tmp/bnn/trunk/
bnn.tex
bnn.bib
bnn.pdf
The above is the recommened structure. I just create the project folder with no sub-directories (such as,
branches, tags, trunks) as shown below:
/tmp/bnn/
bnn.tex
bnn.bib
bnn.pdf
Now, you can import the data into the repository with the svn import command as shown:
$ svn import -m ‘‘Initial Commit’’ tmp file:///path/to/repos
$ svn import -m “Initial Commit” tmp svn+ssh://avishek@shell.cs.utah.edu/uusoc/res/algo/svn
Note: Please note that you need to place your project (say, titled “bnn”) inside some folder (say, “tmp”) and then
import “tmp” and not “tmp/bnn”
3
Client Access:
The following commands would be required on a regular basis to maintain, update and modify your repository.
2
3.1
How to checkout from repository?
To checkout from a remote machine,
$ svn checkout svn://hostname/trunk project
$ svn co svn+ssh://avishek@shell.cs.utah.edu/uusoc/res/algo/svn/bnn
To checkout a particular revision (version):
$ svn checkout -r [revision no.] file:///path/to/repos/trunk project
$ svn co -r 313 svn+ssh://avishek@shell.cs.utah.edu/uusoc/res/algo/svn/bnn
Note: Shortcut for checkout is “co”. So, you can use “$svn co repos destination”
3.2
How to commit your modifications/changes to the repository?
To merge your changes with svn repos,
$ svn commit -m ‘‘commit info/message’’ [files optional]
The following command will merge the entire “bnn” directory:
$ svn ci -m “commit info/message”
However, if you want to merge only the “bnn.tex” then use the following:
$ svn ci -m “commit info/message” bnn.tex
Note: Shortcut for commit is “ci” which stands for checkin (as opposed to “co” for checkout).
3.3
How to add/delete new files/folders to/from repos?
To add new files and folders to svn repos,
$ svn add [files/directories]
$ svn add bnn.new.tex
$ svn ci
To delete files and folders from the svn repos,
$ svn delete [files/directories]
$ svn delete bnn.old.tex
$ svn ci
Note: In either case, the changes are made to your local copy only. In order to make changes to the repos
as well, you need to commit (using svn ci) after addition and deletion operations (as shown above for the
examples).
3.4
How to update your version to the latest version available in the repository?
$ svn update
$ svn update
Note: To update to particular revision: $ svn update -r [revision number]
3.5
How to list contents in the repository?
To list the contents of the svn repo the command svn list can be used with or without the remote path to
the repository.
$ svn list [path to repo]
$ svn list
$ svn list svn+ssh://avishek@shell.cs.utah.edu/uusoc/res/algo/bnn
However, if you have made any changes (added/deleted files) to the repository then the first command may not
always work and it is safe to use the second command (i.e., svn list will the full repo path)
3.6
How to change project name?
To change the project name is a three-step process. First, use the command svn rename to change the project
name in the repository.
$ svn rename [path to repo with old project name] [path to repo with new project name]
3
$ svn rename svn+ssh://avishek@shell.cs.utah.edu/uusoc/res/algo/bnn
svn+ssh://avishek@shell.cs.utah.edu/uusoc/res/algo/bnnNew
Next delete your local copy with the old project name and check out a fresh copy with the new project name.
4
Miscellaneous:
4.1
How to send post-commit mails?
Edit the file “/uusoc/res/algo/svn/hooks/post-commit” and add the following at the end of the last line of the
script:
-m project-name -s [project-label] --diff n --summary author1-email author2-email
-m bnn -s [BNN] –diff n –summary suresh@cs.utah.edu avishek@cs.utah.edu
Note: The convention is to have the project label in all uppercase.
5
SVN Backup:
God forbid, if you ever try hacking the SVN repo1 and end in a mess2 , DON’T PANIC3 !!
The entire “res” space is backed up with backups being taken every hour, day and week. If you ever need to
restore any backed up version (and also want to avoid contacting support for this) then all you need is to replace
the “svn” repo folder with a backed up version from “/uusoc/res/.snapshots”. Restoring backup is a simple
copy operation to your local directory. For details of the naming convention of backup folders, kindly refer to
http://support.cs.utah.edu/index.php?option=com\_content&task=view&id=38&Itemid=66.
1 which
I did
also I did
3 not to mention, I panicked. . .well I had to. . .we didn’t have this tutorial then :)
2 which
4
Download