转自:http://www.shokhirev.com/nikolai/programs/SVN/svn.html#Step-by-step (by Nikolai Shokhirev)
Practical guide to subversion on Windows with TortoiseSVN
by Nikolai Shokhirev
Up: Programming | Next: Repository backup and restore
Contents
- Introduction
- Subversion installation
- TortoiseSVN installation
- Step-by-step setup
- Step 0. Global ignore pattern setting (optional)
- Step 1. Repository (database) creation.
- Step 2. Initial import - Loading your project in the database
- Step 3. Creating a working directory - Connecting your project to the database
- Some remarks
- References
Introduction
There are many excellent books and tutorials on Subversion (SVN) and TortoiseSVN. Some of them are presented in the References section. This tutorial in no way substitutes them. It covers a limited subset of subversion functionality. However, I hope that it simplifies familiarization with SVN.
Subversion is a multi-platform open source version control system (http://subversion.tigris.org/). It consists of a repository database (FSFS or BDB) and several command-line tools. There are GUI front-ends for the Subversion.
The Subversion is designed for project management with several participants. However it can be used to manage personal projects as well.
The current tutorial is limited to a Windows-based local (without a server) SVN.
Subversion installation
Go to the download section of Tigris.org, Open Source Software Engineering Tools ( http://subversion.tigris.org/ ). The latest command-line binaries and libraries for Windows can be found at this location http://www.open.collab.net/
At this point you can start using SVN. It is not necessary to install any GUI program if you are comfortable with using command-line tools.
TortoiseSVN installation
TortoiseSVN installation
TortoiseSVN is a Subversion client, implemented as a windows shell extension, a plug-in to Windows Explorer (http://tortoisesvn.tigris.org/).
The latest version can be downloaded at http://tortoisesvn.sourceforge.net/downloads. For my 32-bit processor I used 32 Bit TortoiseSVN-1.3.5.6804-svn-1.3.2.msi Installer. There is another file, TortoiseSVN-1.3.5.6804-svn-1.3.2.md5 in the download area, which is not required for installation. It contains a checksum of the installer file which is useful if you want to verify that you have downloaded the right installer (and that its not corrupted).
You can download my program HashFile (http://www.shokhirev.com/nikolai/programs/progmisc.html) and verify the installer by checking its MD5 hash (checksum). The checksum must be identical to that found in the TortoiseSVN-1.3.5.6804-svn-1.3.2.md5 file.
This installation is also straightforward, just accept the defaults. The only point of interest is the ASP.Net hack. By default, SVN uses the .svn working directories (Linux style for hidden files).
Default, without the ASP.Net hack | With ASP.Net hack for VS.Net web projects |
This confuses Microsoft ASP.Net and the hack forces SVN to use the _svn working directories instead. Do not install this feature if you are not going to control your ASP.Net projects by Subversion.
Note, that after installation your Windows Explorer has extra buttons in the main menu
and in context (activated by right-clicking) menus.
Step-by-step setup
There are various ways of Subversion management (see the manuals). Now we consider the most typical scenario:
- You have an existing project, which you want to control by Subversion
- This is your personal project on a local Windows computer
In this case you should not worry about security and setting up a server.
Suppose your project resides in C:\Projects\MyProject. It contains files and possibly subdirectories:
Step 0 (Optional). Global ignore pattern setting. You probably do not want to keep track of temporary and some other types of files. Right-click on any folder, and launch TortoiseSVN/Settings:
Alternatively you can click on File/TortoiseSVN/Settings in the Windows Explorer main menu.
In the General section you can list all ignore file types separated by spaces (*.bak *.~*
in the above example). Note that this setting affects all working directories. See the section 5.25 of the User Guide for more options.
Step 1. Repository creation. On your hard drive create the directory for repositories of all your projects, e.g. C:\SVN. Create inside it a sub-directory \MyProject. Right-click on MyProject and choose TortoiseSVN/Create repository here:
Select the default Native FileSystem (FSFS) option and click the OK button:
This converts C:\SVN\MyProject into a repository with the following contents:
So far this is an empty repository, even though Subversion has created several directories and files! We need to fill it with our project files and connect it with our working project directory. All this required several, sometimes counter-intuitive actions.
Step 2. Initial import. Somewhere in your hard drive (e.g. in C:\tmp) create a directory (e.g. \new) with the following three subdirectories:
C:\tmp\new\branches C:\tmp\new\tags C:\tmp\new\trunk
The resulting structure is:
This structure is necessary for more advanced project management, but it does not hurt to create it beforehand. Some tutorials first recommend to import this structure into the repository and later add the project. I recommend the following shortcut.
- Backup your project (C:\Projects\MyProject.), just in case.
- Delete all unnecessary files that are not included in your global ignore list
- Move the contents of \MyProject into the trunk subdirectory (C:\tmp\new\trunk). We will need an empty directory later, anyway.
- Import the 'new' directory into the repository (Right-click/TortoiseSVN/Import):
Selelect URL as file:///C:/SVN/Myproject (forward slashes!):
The "Import finished" message shows C:\tmp\new\* :
Do not worry about the "tmp\new" messages, just check what was actually imported into the repository. Right-click on C:\SVN\MyProject and start TortoiseSVN/Repo-browser:
Navigate to file///C:/SVN/MyProject/trunk:
Note that the files from the ignore list were not imported. Also there is no traces of 'C:\tmp\new'. It is no longer useful and it can be deleted.
Step 3. Creating a working directory. Now you have the repository with all your files and the empty C:\Projects\MyProject (remember, we moved all its contents to C:\tmp\new\trunk?). "To get your hands on blessed, completely approved, and fully loaded Subversion directory, you need to check it out from your repository" [6]. Right-click on C:\Projects\MyProject and choose "SVN Checkout":
Set URL to file:///C:/SVN/MyProject/trunk and Checkout directory to C:\Projects\MyProject:
Press OK. Checkout has finished:
The "blessing" is reflected in the small icons on your project directory and all containing files (and subdirectories).
Such a "blessed" directory is called a working directory. Now you can start working with you project and learn more about Subversion.
Some Remarks
- Sending (checking in) your changes to the repository: Right-click on selected files then "SVN Commit"
- Adding files to the repository. This is a two step process:
- Right-click on selected files then "TortoiseSVN/Add"
- Right-click on selected files then "SVN Commit"
- In addition to books [4] and [5], I also recommend Charlie Calvert's article [6].
- If you use Lavasoft Ad-Aware, do not delete negligible objects: this removes the icon settings from the registry!
- Happy Subversioning!
References
- Subversion Home Page: http://subversion.tigris.org/
- By Hans Dietrich, Version Control for the Standalone Programmer - Part 1. - Excellent Article at Code Project.
- SVN 1-Click setup.- Set up SVN on Windows with a single installer: http://svn1clicksetup.tigris.org/
- Adam Pash, How to set up a personal home Subversion server (with Apache on Windows).
- RapidSVN, a cross-platform GUI front-end for the Subversion revision system: http://rapidsvn.tigris.org/
- TortoiseSVN, a Subversion client, implemented as a windows shell extension: http://tortoisesvn.tigris.org/
- Ben Collins-Sussman, Brian W. Fitzpatrick, C. Michael Pilato. Subversion book: http://svnbook.red-bean.com/
- TortoiseSVN User Guide, which comes with TortoiseSVN.
- Charlie Calvert. Creating Repositories and Projects in Subversion Trunk, Tags, Branches. Codefez: (http://www.codefez.com/Home/tabid/36/ctl/ArticleView/mid/364/articleId/144/Default.aspx)
- An OUCS Guide to TortoiseSVN Client For Windows.http://www.oucs.ox.ac.uk/oucsweb/tortoisesvn.xml
- TortoiseSVN Tutorial. http://www.mind.ilstu.edu/research/complete_inactive/iris4/iris40/developers/svntutorial/
- SVN vs CVS. http://www.pushok.com/soft_svn_vscvs.php
- More SVN links
Buildix includes:
- Subversion for Source Control
- Trac for a Wiki, Bug-Tracker and general Project Management
- Cruise Control for Continuous Integration
Available as LiveCD and VMWare image.