svn build

http://www.cnblogs.com/hitwtx/archive/2011/11/16/2251581.html

 

Common operations of svn import

 

0 Preface
Subversion is a free and open source version management system, which appeared as a substitute for CVS (Concurrent Versions System). This article briefly introduces the installation process of Subversion on Fedora and its basic concepts and usage. You can go to the homepage of the open source book Version Control with Subversion published by O'Reilly and read it online (both in Chinese and English) for more information.

1 Install Subversion on Fedora

[aaronwong@localhost ~]$ sudo yum -y install subversion
[aaronwong@localhost ~]$ rpm -ql subversion
//The above command can query the list of files installed by the subversion package on the system
[aaronwong@localhost ~]$ sudo yum -y install mod_dav_svn
//mod_dav_svn is not required to be installed, it is a plug-in of Apache HTTP Server, the files in your local repository (repository) must pass through it to be shared with others on the network.
//Subversion's component list click here to view.

[aaronwong@localhost ~]$ svn --version
svn, version 1.4.3 (r23084)
compiled on Mar 23 2007, 09:29:55

Copyright (C) 2000-2007 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following Repository Access (RA) modules can be used:

* ra_dav : Module for accessing repositories via WebDAV (DeltaV) protocol.
- handle "http" scheme
- handle "https" scheme
* ra_svn : A module for accessing the repository using the svn network protocol.
- Handle "svn" scenarios
* ra_local : Repository module that accesses local disk.
- handle "file" scheme


2 Use Subversion to manage local projects
As a program developer, we don't have to understand all aspects of Subversion's features. Our purpose is to use it for easy and simple version management of our projects. Therefore, it is strongly recommended to read Subversion Quick-Start Guid and Basic Usage .
The following is an example of the author referring to the above Guide to perform a simple version management of a local project. Assume the project name is hello.
(1) Establish the subversion warehouse of the local project hello Subversion
centralizes the data of each version of the project in a warehouse (repository). Suppose we want to create a local project, called hello. In order to use subversion to version it, we must first create a repository for the project.

[aaronwong@localhost ~]$ svnadmin create .subversion/repos/hello
//Subversion will generate a ~/.subversion directory after installation. Here, we will build the project hello data warehouse in the ~/.subversion/repos/hello directory.

[aaronwong@localhost ~]$ ls -p .subversion/repos/hello/
conf/dav/db/format hooks/locks/README.txt


(2)按照subversion的要求组建本地工程hello的工作目录
假定工程hello的顶层目录为~/projects/hello(这里~代表/home/aaronwong/),则应如下组建工程的工作目录:

~/projects/hello/branches
~/projects/hello/tags
~/projects/hello/trunk/
hello.c
//trunk目录是实际上的工程顶层目录,工程中的所有文件和文件夹都在该目录下组织。
[aaronwong@localhost ~]$ cd projects/hello/
[aaronwong@localhost hello]$ ls -p
branches/ tags/ trunk/
[aaronwong@localhost hello]$ cat trunk/hello.c
//This isa originalversion.

#include <stdio.h>

int main()
{
printf("Hello world!\n");

}


(3)将本地工程hello导入本地的Subversion的工程仓库
由于是首次导入,因此要加信息-m "initial import"。

[aaronwong@localhost trunk]$ svn import ~/projects/hello/ file:///home/aaronwong/.subversion/repos/hello/ -m "initial improt"
新增 /home/aaronwong/projects/hello/trunk
新增 /home/aaronwong/projects/hello/trunk/hello.c
新增 /home/aaronwong/projects/hello/branches
新增 /home/aaronwong/projects/hello/tags

提交后的版本为 1。

注意,完成导入后,原目录~/projects/hello并不转换为“工作副本(working copy)”,而且该项目已经转由该仓库接管,即该仓库中已经包含了首次导入的工程的所有信息,与源目录~/project/hello再无任何关系,我 们完全可以删除这一目录而不必担心丢失工程项目数据。注意,如果源目录并不是一个“工作副本”,那么就无法用svn进行管理,在其中所作的任何变动都无法 提交到仓库。
要用subversion对工程进行版本管理,那么工程项目的开发必须在一个“工作副本”中进行,即首先要从仓库获取一个“工作副本”。

(4)工程开发过程中的版本管理与控制
使用subversion对工程进行版本管理的一般流程如下:
a)建立工程的数据仓库,并导入工程的最初版本(前面已经完成);
b)从仓库获取一个“工作副本”(svn checkout,可以获取最新版本也可以获取以前的某个版本),在这个“工作副本”中进行工程开发,修改完毕将变动提交到仓库。
下面简单介绍b)步骤。
由于工程hello已经导入到仓库,因此原目录可以删除。我们删除原目录,并从仓库获取工程hello的一个“工作副本”(working copy);当然,如果你当心这样做会造成数据丢失,完全可以重新建立一个目录,将“工作副本”保存到那里。

[aaronwong@localhost projects]$ rm -rf hello/
[aaronwong@localhost projects]$ svn checkout file:///home/aaronwong/.subversion/repos/hello/trunkhello
A hello/hello.c
取出版本 1。
//注意,我们用红色标出了"trunk",如果不指定这一目录,则会取出除工程源文件外的其他不必要的目录如branches和tags。
[aaronwong@localhost projects]$ ls -a hello/
. .. hello.c .svn
//可以看到“工作副本”下有一个.svn隐藏目录,其中就包含了subversion用來进行版本管理的信息。


下面可以对工程hello的内容进行编辑和修改。注意,如果要在工程中增加或删除某一文件或目录(包括复制和移动),必须使用svn add/delete/mkdir/copy/move等相关命令进行标记。

[aaronwong@localhost hello]$ pwd
/home/aaronwong/projects/hello
[aaronwong@localhost hello]$ vim hello.c
[aaronwong@localhost hello]$ cat hello.c
//This isthe secondversion.

#include <stdio.h>

int main()
{
printf("Hello world!\n");
return;
}
[aaronwong@localhost hello]$ mkdir doc
[aaronwong@localhost hello]$ vim doc/readme.txt
[aaronwong@localhost hello]$ svn add doc
A doc
A doc/readme.txt
//说明:如果svn add的对象是一个目录,则该目录及其子目录和其下的文件都会被添加到工程。


对工程编辑完毕,你可以检查一下该次编辑对工程(实际上是对你的"工作副本")做了哪些改动。

[aaronwong@localhost hello]$ svn status
M hello.c
A doc
A doc/readme.txt
[aaronwong@localhost hello]$ svn diff
Index: hello.c
===================================================================
--- hello.c (版本 1)
+++ hello.c (工作副本)
@@ -1,10 +1,10 @@
-//This is a original version.
+//This is the second version.

#include <stdio.h>

int main()
{
printf("Hello world!\n");
-
+ return;
}

Index: doc/readme.txt
===================================================================
--- doc/readme.txt (版本 0)
+++ doc/readme.txt (版本 0)
@@ -0,0 +1,2 @@
+This is an example for subversion tutorial.
+
//可以看到,svn diff提供了更详细的改动信息,并且很容易的将该命令的输出重定向为一个patch补丁。


检查确认无误后,便可提交此次更改,同时要附加此次更改的说明注释信息。

[aaronwong@localhost hello]$ svn commit -m "documents added."
新增 doc
新增 doc/readme.txt
正在发送 hello.c
传输文件数据..
提交后的版本为 2。

现在工程仓库中已经保存了上面所提交的版本2的工程的所有信息,因此,上面的“工作副本”也可以被删除:当然,如果下次你还要继续使用这个“工作副本”进 行工作,则可以保留这个副本,不过需要注意的是,如果你是在一个开发团队中,开发团队的任一成员都可能在你不知情的情况下更新了工程版本,因此,在团队开 发中,进入已有的“工作副本”进行编辑前,应该先使用"svn update"命令将当前“工作副本”更新到仓库中的最新版本。

3 使用svn获取开源项目源代码
这实际上是获取一个“工作副本”的过程。例如我需要下载ffmpeg的最新源代码,就可以使用svn checkout命令来完成:

[aaronwong@localhost ~]$ svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
A ffmpeg/configure
A ffmpeg/Doxyfile
A ffmpeg/ffmpeg.c
A ffmpeg/vhook
A ffmpeg/vhook/imlib2.c
A ffmpeg/vhook/drawtext.c
A ffmpeg/vhook/fish.c
A ffmpeg/vhook/null.c
......



这篇文章仅仅是Subversion的使用入门,其实它的功能非常丰富和强大,如果你已经对它产生了兴趣,强烈推荐您阅读subversion在线书籍,您还可以进入网络社区或论坛与朋友进行更深入的讨论。

一个不会敲代码的程序员

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326939779&siteId=291194637