转 八步学SVN

简介:

 This week I was attending a CI training course about svn. Here I'd like to share what I have learnt. As I am an absolutely green bird to svn, this post only covers those most common usages.

(1) Create a repository

      Given that we already have a project with a directory structure as below:

          my-project

           |____branches

           |____tags

           |____trunk

           | |____etc

           | | |____conf.txt

           | |____source.txt 

     Now we want to create a svn repository to accomodate this project, first we need to initialize an empty repository:

svnadmin create path/to/svn-repository

 

(2) Run SVN server

svnserve -d -r path/to/svn-repository


     The "-d" option tells svn server to run as a deamon, and the "-r" option tells the server the location of our repository, now we are able to access our repository using URL: svn://localhost. In order to allow any anonymous user to have both read and write permission(this may not be a good practice, we do so just for convenience), we can modify the configuration file named svnserve.conf located under the repository's conf subfolder, comment in these two lines:

anon-access = write
auth-access = write

     Now we are able to read and write to the repository without providing a user account.


(3) Import a project 

     Once the repository has been created, the next step is to import our project into the repository:   

svn import path/to/my-project svn://localhost


     An svn repository for our project has been created, you may take a look at our newly imported project in the repository with:

svn list svn://localhost
     branches/
     tags/
     trunk/

 

     As we can see, the directory structure in the repository is exactly the same as the original project.

 

(3) Checkout the code

     We don't have to pay much attention to our original project any more as svn repository already contains the whole project, then if someone wants to make a working copy, she/he can make a checkout:       

svn checkout svn://localhost/trunk working-trunk


     The command above checks out the trunk folder to working-trunk, other folders can also be checked out using the correspond subfolder name, or the whole project can be checked out with no folder names. 

 

(4) Make some change

     Now switch to working-trunk and make your own change, you can modify a file directly, or add a new file using "svn add filename", delete a file using "svn delete filename", and rename a file using "svn rename old-filename new file-name".

 

(5) Checkin the changed code

     Once we are confident enough to publish our change to the repository, we can check in our code. But before we check in our code, we need to pull the latest code from repository given that others may have checked in their code, we can use the command below to update our own working copy:       

svn update


     If we are lucky as there's no conflict between our own change and those pulled from the repository, we can check in our code directly:     

svn commit -m "description of my change"


(6) Manage merging

     In step (5), we were praying our own change doesn't overlap with the changes made by others, but there are times our change do overlap with others' code and conflict occurs when someone modified the same lines of code as ourselves do, under such circumstances we need to merge the conflict manually. If we try to update our own working copy  when there is conflict, we will get the following information:

          Conflict discovered in 'source.txt'.

          Select: (p) postpone, (df) diff-full, (e) edit,

                  (mc) mine-conflict, (tc) theirs-conflict,

                  (s) show all options:

     There are sevral options to choose, with "postpone" to skip editing the conflict for the time being, "edit" to nevigate us to edit the conflict right now etc.. If we choose "(p)postpone", the conflict will remain there for later resovle, and our conflicting file(source.txt) will be marked in its content as having conflict:

           ............

          <<<<<<< .mine

          this is modified by me

          =======

          this is modified by another person

          >>>>>>> .r6

          ............ 

     The content between "<<<<<<<<" and "=======" shows our own change while the content between "======"  and ">>>>>>" shows changes make by others. Now if we want to keep both changes, what we can do is to edit the conficting file as below:

          .............

          this is modified by me

          this is modified by another person

          .............

     and then tell svn the file has been merged by using:              

svn resolve --accept=working source.txt


     next, don't forget to commit the merge:       

svn commit -m "merge source.txt"


(7) Branching

     svn uses "svn copy" to create branches, chances are that we are at some stage of trunk development and we want to introduce a new feature without influencing the trunk, making a new branch for that feature is a good choice. To create a branch in svn:       

svn copy svn://localhost/trunk svn://localhost/branches/new-feature -m "create a new branch named new-feature"


     Now we can check out the new branch and implement new feature in it:      

svn checkout svn://localhost/branches/new-feature

 

(8) Tagging

     Tagging in svn is implemented in the same way as branching, yet tagging differs from branching is that tagging usually serves as a purpose to create a stable version from trunk.



目录
相关文章
|
安全 虚拟化
GIC规格学习(一)
GIC规格学习(一)
479 0
|
存储 数据可视化 Serverless
使用蒙特卡罗模拟的投资组合优化
在金融市场中,优化投资组合对于实现风险与回报之间的预期平衡至关重要。蒙特卡罗模拟提供了一个强大的工具来评估不同的资产配置策略及其在不确定市场条件下的潜在结果。
657 1
|
前端开发
Vue3/React 动态设置 ant-design/icons 图标
Vue3/React 动态设置 ant-design/icons 图标
811 1
|
8月前
|
JSON 监控 API
速卖通商品列表接口(速卖通API系列)
速卖通提供商品列表API,开发者可通过关键词、类目、价格范围等条件获取商品标题、价格、销量等基本信息。使用前需注册开发者账号、创建应用并授权获取access_token。Python示例代码展示了如何调用接口,返回JSON格式数据,包含商品列表、总数、页码等信息。应用场景包括商品监控、数据分析和个性化推荐。注意API会更新,请参考官方文档。
|
存储 安全 程序员
|
机器学习/深度学习 编解码 自然语言处理
重磅!新增 13 种 Transformer 方法,火速收藏
如今,Transformer 这把火已经烧到了计算机视觉领域,可以说成为今年最大的热点。本着全心全意为社区服务的精神,OpenMMLab 当然不会对此无动于衷。 为了方便大家研究学习,我们基于 MMCV ,在OpenMMLab 6个方向的 repo 中复现了 13 种基于 Transformer 的方法,快来看看有没有你需要的吧。
1006 0
重磅!新增 13 种 Transformer 方法,火速收藏
|
供应链 数据挖掘
数据分析五大指标分类
数据分析中常见的指标分类方法
|
机器学习/深度学习 弹性计算 Cloud Native
阿里云神龙获2023年度CCF技术科技进步一等奖
阿里云神龙获2023年度CCF技术科技进步一等奖
583 0
|
机器学习/深度学习 算法
大模型如何实现对股票的未来走势预测?
这是一个很好的问题。目前,有很多方法可以预测股票价格,其中一种是使用机器学习算法来预测未来的股票价格。这些算法从平均和线性回归等简单的算法开始,然后转自动ARIMA和LSTM等高级技术。
1454 0
|
消息中间件 运维 Dubbo
重新理解Martin Fowler对微服务的定义
重新理解Martin Fowler对微服务的定义
重新理解Martin Fowler对微服务的定义