SVN服务器及客户端的简单使用

来源:互联网 发布:mac好用的软件 编辑:程序博客网 时间:2024/05/17 22:21

转自 http://www.codeproject.com/KB/winsdk/SubversionOnWindows.aspx


Introduction

Subversion is an Open Source version control system. This means that you can get a copy and use it for free. This article is about using Subversion and not about how to modify and/or build it. A version control system (vcs) is a way to track changes to a set of files. Typically, we think of the files as containing programming source code, but it could also be used to track any sort of files that are subject to modification by one or more persons.

In this article, I will describe my experiences in setting up Subversion on Windows XP for tracking my ProjectMIDIsource code.

Quick start

You can download the Subversion code and documentation from here.

Background

When I first started looking at Subversion I was a bit confused by the overall Unix perspective used in the documentation. Most examples list Unix syntax such as forward slashes instead of Windows backslashes, and the absence of any drive letters.

Having recently written a couple of articles for CodeProject, I decided to create this article to record my experiences in getting Subversion up and running in a Windows XP environment.

Installing Subversion

Installing Subversion was quite easy. Simply download the Windows installer from the Subversion website and run it. Note that the source is also available. You can download it and build it yourself. For this article, I simply downloaded the Windows installer svn-1.3.0-setup.exe.

Creating a repository

A repository is a folder on your system where you will keep your code. There are a couple options for how your code is stored. The older method uses a Berkley BSD database. The newer and default method uses simple flat files, meaning that directory trees are created in the repository directory to store each version of your file. I recommend using the default flat file format.

To create the repository, open a command prompt window and type the following command:

svnadmin create /path/to/repos

I selected to put the repository in a new folder named SvnRepos the root of my C: drive, so the command I used was:

svnadmin create C:\SvnRepos

You of course can choose any convenient location that you wish. I will use C:\SvnRepos in my examples in this article.

Adding your source code the first time

The next step after installing subversion on your system is to add your source code. Use the following command:

svn import filesdir     file:///path/to/repos/myproject -m "initial import"

On my system, my code was located in multiple folders under the C:\ProjectMidi_src folder. I used the command:

svn import projectmidi_src     file:///c:/SvnRepos/ProjectMidi -m "initial import"

You can verify that the import created the new project using the svn list file:///c:/SvnRepos command.

Creating a working copy to work on

Now that your code is checked into the repository, you need to create a working copy to use in making your changes. This is done using the svn checkout command. I created my working directory at c:\ProjectMidi, so the following command was used:

svn checkout file:///c:/SvnRepos/ProjectMidi ProjectMidi

You may have noticed by now that the forward and backslashes are a bit confusing. I noticed the same thing. That's a big part of why I'm writing this article.

Making changes to your working copy

Now use the working copy you just created to make your changes, build, and perform testing. You do not have to notify Subversion about the changes that you make to the files. It will detect this automatically. However, if you add,copymove, or delete any versioned files then you will need to use the corresponding svn addcopymove, ordelete command. To check what changes have been made, use the svn status command.

Publishing your changes

Once you have made changes to your working copy and verified that everything is working correctly, you will need to write your changes to the repository. Subversion refers to this as "Publishing" your changes. You use the svncommit command to do this. This command writes the changes in your working copy back to the repository.

Updating your working copy with other changes

If somebody else updates the repository while you have a working copy open, you can merge those changes from the repository to your working copy using the svn update command.

Summary

And that covers the basics of using Subversion. There are a lot of other commands and features which I won't go into in this article. Check out the documentation on the Subversion website. Hopefully this article has helped you with specific Windows syntax. Before you go much further though, you need to know about another program which can make using Subversion on Windows a lot easier. That program is TortoiseSVN.

TortoiseSVN: A Graphical User Interface

So far in this article we've been working with the UNIX-style command line interface. If you'd prefer to perform Subversion operations directly within a Windows Explorer window, you can use TortoiseSVN. This is another open source program. You can download it from here. After installing TortoiseSVN, you should see a difference when viewing your working copy directories in Windows Explorer. The picture below shows my ProjectMIDI working copy after installing Tortoise:

Notice that the files I have checked out now have a green checkmark next to them.

As I make changes to these files, the green checkmarks will turn into red exclamation marks, indicating that they've been modified. Simply right-clicking on them will give me the menu shown above which can be used to commit the changes or any of several other options.

Points of interest

I wrote this article primarily to improve my understanding of Subversion. I hope that you've learned something also. I've tried in this article to show how easy it can be to use Subversion and TortoiseSVN to manage and share your own project files, whatever that project may be.

Credits and references

During this learning experience, I found the following references very helpful:

  • The official Subversion website (of course).
  • The TortoiseSVN website.
  • The Subversion Cheat Sheet. This site was very helpful in figuring out the Windows syntax.

History

  • 10th Feb, 2006
    • Uploaded article to CodeProject.
  • 4th Feb, 2006
    • Began working on the article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

rlisle

Software Developer (Senior)

United States United States

Member
Ron is a senior software engineer.
His hobbies include riding motorcycles, travel, and scuba diving.
 
He enjoys learning about science, particularly quantum physics and cosmology.
 
He is active with his church where he plays drums and keyboards with the contemporary church band each week. 
He also designed and maintains his church and band websites (http://TheRockUMC.org and http://TheRockBand.org).

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 微信文件被清理怎么办 老婆与别人聊暧昧话题怎么办 微信不小心删了聊天记录怎么办 当聊天没话题了怎么办 老婆和别人频繁聊天老公怎么办 qq上把人屏蔽了怎么办 注册微信验证码发不出去怎么办 两个人在一起没有话题怎么办 两个人聊天没话题怎么办 qq邮箱限制信用卡账单怎么办 和朋友聊天没话题怎么办 跟朋友聊天没话题怎么办 和朋友聊天找不到话题怎么办 qq加好友忽略了怎么办 微信加好友收不到验证消息怎么办 陌陌距离乱了怎么办 qq不能点赞了怎么办 快递发货地址写错了怎么办 订的海鲜不发货怎么办 拉人进群频繁了怎么办 qq群邀请过于频繁怎么办 qq一直被拉进群怎么办 qq号被冻结解封不了怎么办 2018qq自动进群怎么办 手机视频传到电脑倒着怎么办 qq群图片过期了怎么办 q号加不了群怎么办 q号加不了好友怎么办 q号被冻结了怎么办 qq群200人满了怎么办 畅聊之火消失了怎么办 手机版WPS打开文档空白怎么办 空白表格怎么打印不出来怎么办 微信朋友太少怎么办 js和CSS加载失败怎么办 熹妃q传密码忘了怎么办 苹果手机淘宝占用空间大怎么办 苹果相册储存空间不足怎么办 企业网银里的收款名单丢失怎么办 发邮件发错了怎么办 qq群成员满500了怎么办