1. 程式人生 > >SVN 入門: 將已有檔案目錄加入svn版本控制

SVN 入門: 將已有檔案目錄加入svn版本控制

轉自: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

  • 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

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-endsfor 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/downloads/subversion/. Download the installer. The installation of SVN into the default directory C:\Program Files\Subversion is pretty straightforward. 

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 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: 
    1. Right-click on selected files then "TortoiseSVN/Add"
    2. 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 , do not delete negligible objects: this removes the icon settings from the registry!
  • Happy Subversioning!

References

See also: Buildix - The Agile development platform on a disk: http://buildix.thoughtworks.com/.

Buildix includes:

Available as LiveCD and VMWare image.