初学者使用Subversion(SVN)进行版本跟踪

tortoise-48185613_8cce892353_b

Have you ever wanted to work on a project with the ability to track your changes as well as revert them? How-To Geek explains How-To use the popular version tracking system, Subversion (a.k.a SVN).

您是否曾经想过能够跟踪更改并还原更改的项目? How-To Geek解释了How-To如何使用流行的版本跟踪系统Subversion(又名SVN)。

Image by Clearly Ambiguous

图片由明显模糊

预录 (Prelog)

This guide will aim to give you the ability to use the subversion client in general, and, if you have one, on your *DD-WRT router. This guide is by no means a definitive guide for Subversion and a lot of information can be found on the Subversion Red Book. This guide is only intended to give you the shorthand answer to the most basic of questions.

本指南旨在使您能够总体上使用Subversion客户端,如果有的话,也可以在* DD-WRT路由器上使用。 该指南绝不是Subversion的权威指南,并且可以在Subversion Red Book上找到很多信息。 本指南仅旨在为您解答最基本的问题。

总览 (Overview)

There could be numerous reasons why you would want to be able to “checkout” the latest code for a software project that uses a versioning system. Doing so enables you to benefit from the latest still unreleased changes, help with testing and even development. In this guide, we will go over some basic SVN terminology, show how to install the SVN client on Linux, Windows and if you have one your OPKG enabled DD-WRT router. We’ve also included an example of a project you can checkout and use for said router.

可能有很多原因,您希望能够“签出”使用版本控制系统的软件项目的最新代码。 这样做使您可以从尚未发布的最新更改中受益,帮助进行测试甚至开发。 在本指南中,我们将介绍一些基本的SVN术语,展示如何在Linux,Windows以及如果您有一个启用OPKG的DD-WRT路由器上安装SVN客户端。 我们还提供了一个项目示例,您可以检出该路由器并将其用于该路由器。

什么是Subversion? (What is Subversion?)

Subversion is by no means the only version control system in existence and alternatives include Git (which was created by Linus Torvalds the Linux kernel founder), Mercurial and PerForce to name a few. With that said, it is one of the free ones, it’s mature and is extensively used world wide.

Subversion绝不是唯一存在的版本控制系统,替代品包括Git (由Linux内核创始人Linus Torvalds创建),Mercurial和PerForce等。 话虽如此,它是免费的之一,它已经成熟并且在世界范围内被广泛使用。

Out of the Subversion “Red Book”:

走出颠覆的“红皮书”

Subversion is a free/open source version control system (VCS). That is, Subversion manages files and directories, and the changes made to them, over time. This allows you to recover older versions of your data or examine the history of how your data changed. In this regard, many people think of a version control system as a sort of “time machine.”

Subversion是一个自由/开源版本控制系统 (VCS)。 也就是说,Subversion随时间管理文件和目录以及对其进行的更改。 这使您可以恢复数据的旧版本或检查数据更改的历史记录。 在这方面,许多人将版本控制系统视为一种“时间机器”。

Note: This book is the ultimate collection of knowledge about subversion and you are advised to refer to it on all Subversion related topics.

注意: 本书 有关Subversion的最终知识的汇总,建议您在所有Subversion相关主题上进行参考。

什么是版本控制? (What Is Versioning?)

Versioning is a process where the state of a project at a point in time is saved. This sort of procedure is often used to manage software development, so that work can continue to improve the project or add features, while being able to track what has changed from the last overall “save” point. To elaborate, this sort of procedure can be useful for a single person but even more so for a group of people, all working on the same project. This is because, usually, when working on a project as a group, there is a distribution of responsibilities and different people change different aspects of the project. Without a versioning mechanism, it would be very difficult to keep everyone in sync on the latest working changes from everyone else.

版本控制是保存项目在某个时间点的状态的过程。 这种过程通常用于管理软件开发,因此工作可以继续改进项目或添加功能,同时能够跟踪自上次总体“保存”点以来发生了什么变化。 详细地说,这种过程对于一个人可能是有用的,但对于在同一项目上工作的一群人则更有用。 这是因为,通常,当一个团队作为一个团队工作时,职责是分散的,并且不同的人会改变项目的不同方面。 没有版本控制机制,要使每个人都与其他人保持最新的工作变化同步就非常困难。

术语 (Terminology)

The Repository The repository is the location where all the data from all the various places is saved. In the subversion world, from the client’s point of view, it is the server which holds the database of the project. This database contains all the files that are part of the project with all of their past versions.

存储库 存储库是保存来自各个位置的所有数据的位置。 从客户的角度来看,在Subversion的世界中,服务器是保存项目数据库的服务器。 该数据库包含项目中所有的文件及其所有以前的版本。

Revision

修订版

When a repository is created, it is given the revision number of zero (0). This number is incremented by one(1) every time a commit is performed. The revision number is global for the repository. That is, that there is no individual revision number for individual files in the repository, even if nothing changed in that file for that specific commit.

创建存储库时,其修订号为零(0)。 每次执行提交时,此数字都会增加一(1)。 版本号对于存储库是全局的。 也就是说,即使存储库中的特定提交没有任何更改,存储库中的各个文件也没有单独的修订号。

The Working copy

工作副本

A working copy is a local copy (or “checkout”) of a particular version. Usually this version when checked-out is the “latest” one (also called a “head“), but a previous one can be requested. The User may do with the local copy anything that he/she desires, with knowledge that, at worst, they could just checkout the code again. Moreover, this copy is “private”. This is because until you either update or commit your copy, you will not see other people’s changes, nor will they see yours.

工作副本是特定版本的本地副本(或“签出”)。 通常,此版本在签出时是“最新”版本(也称为“ head ”),但可以要求使用先前版本。 用户可以使用本地副本进行他/她想要的任何操作,但要知道,在最坏的情况下,他们可以再次签出代码。 此外,此副本是“私人”的。 这是因为除非您更新或提交副本,否则您将看不到其他人的更改,也不会看到他们的更改。

Updating & Conflict resolving

更新和解决冲突

A Local working copy can be updated. That is, If you “checked out” a certain version, and while you were working, the version on the repository has been updated, you can update your working copy to the latest. In fact, the server will prevent you from committing your changes before you update to the latest version to match the repository. This is done in order to force you to resolve conflicts locally, before you even think of committing changes to the repository.

本地工作副本可以更新 。 也就是说,如果“签出”某个版本,并且在工作时,存储库中的版本已更新,则可以将工作副本更新为最新版本。 实际上,在更新到最新版本以匹配存储库之前,服务器将阻止您提交更改。 这样做是为了迫使您在考虑将更改提交到存储库之前,就地解决冲突

Merging

合并中

Merging refers to the process by which, changed code is blended into one version. It may also entail resolving conflicts.

合并是指将更改的代码混合到一个版本中的过程。 它还可能需要解决冲突。

Commits

提交

Committing is the process in which the changes you have made to your local copy will be merged back into the repository. This is the most perilous part of the process, as it is here that changes you have made, might impact other people using the same repository. That is why this is usually done after some consideration, with the team’s consensus and after you’ve resolved any merging conflicts.

提交是将您对本地副本所做的更改重新合并到存储库中的过程。 这是该过程中最危险的部分,因为您所做的更改可能会影响使用同一存储库的其他人。 这就是为什么通常在经过考虑之后,在团队达成共识之后,并且在您解决了所有合并冲突之后才进行此操作的原因。

The Workflow

工作流程

The most basic workflow from the user’s perspective when using subversion is this:

从用户的角度来看,使用Subversion时最基本的工作流程是:

1. Checkout the existing code (usually the “head“). 2. Make changes, add files and generally develop the code. 3. Update to the latest version, to make sure your local copy is in sync with the updates on the repository. 4. Locally merge and resolve conflicts if necessary. 5. Commit the merged changes into the repository. 6. GoTo step 2.

1.签出现有代码(通常为“ head ”)。 2.进行更改,添加文件并通常开发代码。 3.更新到最新版本,以确保您的本地副本与存储库中的更新同步。 4.如有必要,在本地合并并解决冲突。 5.将合并的更改提交到存储库中。 6.转到步骤2。

让我们破解 (Lets get cracking)

Install the Client

安装客户端

In order to be able to use subversion, you need to install the client on your machine.

为了能够使用Subversion,您需要在计算机上安装客户端。

On Linux

在Linux上

You need only to install the package. On Ubuntu/Mint, this would be done with:

您只需要安装该软件包。 在Ubuntu / Mint上,这可以通过以下方式完成:

sudo aptitude install subversion

sudo aptitude安装颠覆

On DD-WRT

在DD-WRT上

If you’ve followed the “How To Install Additional Software On Your Home Router (DD-WRT)“, you are able to install the svn client by simply issuing:

如果遵循“ 如何在家庭路由器(DD-WRT)上安装其他软件 ”的说明,则只需发出以下命令即可安装svn客户端:

opkg update; opkg install subversion-client

opkg更新; opkg install subversion-client

On Windows

在Windows上

While we deep geek users may start to forget that the GUI even exists at times, not everyone has. If you want to use a windows client to connect to an SVN repository, by far the most popular one is “Tortoise“. To use it, simply download the program and install in the regular “next, next, finish” fashion.

尽管我们极客极客可能会开始忘记GUI有时甚至存在,但并非所有人都有。 如果要使用Windows客户端连接到SVN存储库,到目前为止,最受欢迎的是“ Tortoise ”。 要使用它,只需下载该程序并以常规的“下一步,下一步,完成”方式进行安装。

Create the “repository”

创建“存储库”

While we will not go into to much detail on how to setup a subversion server in this guide, the Google alternative is not a bad start for the novice user. To create a Google repository:

虽然我们不会在本指南中详细介绍如何设置Subversion服务器,但对于初学者来说,使用Google替代方案并不是一个不错的开始。 要创建Google存储库:

  • Head over to the Google Code hosting website and “create” a new project.

    转至Google Code托管网站并“创建”一个新项目。

  • In the next page, fill in the required fields and select the type of “version control system” to be subversion.

    在下一页中,填写必填字段,然后选择要版本化的“版本控制系统”的类型。

    Note: You may want to glance over what is the difference between the licenses Google offer, before you select one for the project.

    注意:在为项目选择一个之前,您可能希望浏览一下Google提供的许可之间的区别。

  • Click “Create project”.

    点击“创建项目”。
“Checkout” your working copy “结帐”您的工作副本

Once your project has been created, you Should be able to find the instructions on how to access it in the “Source” tab.

创建项目后,您应该能够在“源”选项卡中找到有关如何访问它的说明。

The nice thing about Google code, is that it will enable an anonymous read-only version for your project. If you don’t want to deal with the hassle of creating your own project, you may anonymously checkout this writer’s repository.

关于Google代码的好处是,它将为您的项目启用匿名只读版本。 如果您不想处理创建自己的项目的麻烦,则可以匿名签出该作者的存储库。

One note about the hotfortech project: This project is meant to be a wrapper for the features that have been added to DD-WRT on How-To Geek (that I personally use) plus some personal tweaks. While this project is geared to work in conjunction with the articles published here on howtogeek, it is still my private project. That is, it’s highly suited to my Buffalo router (AR71xx architecture), my personal whims and is prone to the occasional borkage.

关于hotfortech项目的一个注释:该项目是对How-To Geek(我个人使用)添加到DD-WRT的功能的包装,以及一些个人调整。 尽管该项目旨在与此处发布的howtogeek文章协同工作,但这仍然是我的私人项目。 也就是说,它非常适合我的Buffalo路由器(AR71xx架构),是我个人的心血来潮,并且偶尔会出现麻烦。

On Linux/DD-WRT

在Linux / DD-WRT上

Create the directory to work in, for example on DD-WRT, that could be:

创建要在DD-WRT上使用的目录,该目录可以是:

mkdir -p /jffs/svn; cd /jffs/svn

mkdir -p / jffs / svn; cd / jffs / svn

The full command on Linux consists of the SVN command itself, the “checkout” directive, the address of the repository and the directory to checkout too. Create an empty directory and execute the command below:

Linux上的完整命令包括SVN命令本身,“ checkout”指令,存储库的地址以及要检出的目录。 创建一个空目录并执行以下命令:

svn checkout http://hotfortech-dd-wrt.googlecode.com/svn/trunk/ hotfortech-dd-wrt-read-only

svn checkout http://hotfortech-dd-wrt.googlecode.com/svn/trunk/ hotfortech-dd-wrt-read-only

Do note that in the example above, the read-only version is being checked out. If you opted to create your own repository, you will need to use the httpS link.

请注意,在上面的示例中,只读版本已签出。 如果选择创建自己的存储库,则需要使用httpS链接。

On Windows

在Windows上

Because tortoise is a shell extension, you will need to use the Windows file explorer’s context menu (right-click) to use it. In fact, if you try to invoke it from the start menu, you will get:

由于tortoise是shell扩展,因此您将需要使用Windows文件浏览器的上下文菜单(单击鼠标右键)来使用它。 实际上,如果尝试从开始菜单调用它,则会得到:

  • Create an empty directory.

    创建一个空目录。
  • Right click in it to bring up the context menu.

    右键单击它以弹出上下文菜单。
  • Select “SVN Checkout”:

    选择“ SVN Checkout”:

  • Copy & paste the link for project (if you have one) into the “URL” Textbox:

    将项目链接(如果有的话)复制并粘贴到“ URL”文本框中:

  • Depending on the size of your project this may take a while, but when the “Checkout” has been completed you should see something like:

    根据您的项目的大小,这可能需要一段时间,但是当“结帐”完成时,您应该会看到类似以下内容的信息:

  • You may start developing.

    您可以开始开发。

“Update” & “Merge” your working copy If your working on the code with colleagues, or you your self are updating the code from several locations (i.e. laptop, desktop or even router), you will have to update your working copy before you commit the latest changes.

“更新”和“合并”您的工作副本如果您与同事一起处理代码,或者您自己在多个位置(例如笔记本电脑,台式机甚至路由器)更新代码,则必须先更新工作副本提交最新更改。

On Linux/DD-WRT

在Linux / DD-WRT上

The command to do this on these POSIX systems is simply:

在这些POSIX系统上执行此命令的命令很简单:

svn up

svn

On Windows

在Windows上

  • Right click in the working directory and select “SVN Update”:

    右键单击工作目录,然后选择“ SVN更新”:

  • If you encounter conflicts, try following the on screen instruction and use your judgment as to what to do about them.

    如果遇到冲突,请尝试按照屏幕上的说明进行操作,然后根据自己的判断来解决这些问题。

“Commit” your changes That is it, you should be conflict free and ready to update the repository with your changes. The one point to note here is that it is a common practice to add a “log” message to the commit, as to be able to easily recall why the changes were made. In fact, Google’s repository makes this a mandatory pre-requirement to committing.

“提交”更改就是这样,您应该没有冲突,并准备使用您的更改来更新存储库。 这里要注意的一点是,将常见的做法是在提交中添加“日志”消息,以便能够轻松回忆起进行更改的原因。 实际上,Google的存储库使这成为提交的强制性先决条件。

On Linux/DD-WRT

在Linux / DD-WRT上

This is an example of the commit I’ve made to the hotfortech project that upped it to version 19:

这是我对hotfortech项目所做的提交(将其升级到版本19)的一个示例:

svn commit -m “updated to reflect new ant-ads pack link”

svn commit -m“已更新,以反映新的ant-ads pack链接”

On Windows

在Windows上

  • Right click in the working directory and select “SVN Commit”:

    右键单击工作目录,然后选择“ SVN Commit”:

  • You should be greeted by a window that enables you to note a log message:

    您应该被一个允许您注意日志消息的窗口欢迎:

  • Hit OK and when prompted for a password, give the Google generated password.

    点击确定,当提示您输入密码时,输入Google生成的密码。
  • If the commit was successful,you should see something like:

    如果提交成功,您应该看到以下内容:

  • That is it, you should be able to commit like a BOSS.

    就是这样,您应该能够像BOSS一样进行提交。

Final remarks This should be enough to get you started. You are advised to read the SVN reference books to get a deeper and better grasp on all of SVN’s usages, options and caveats. Also, we remind you (again) that subversion is NOT the only version control system out there and GIT (which was created by Linus Torvalds the Linux kernel founder) seems to be gaining popularity in recent years.

结束语这应该足以让您入门。 建议您阅读SVN参考书,以更深入,更好地掌握SVN的所有用法,选项和注意事项。 另外,我们再次提醒您,Subversion并不是唯一的版本控制系统, GIT (由Linux内核创始人Linus Torvalds创建)近年来似乎越来越流行。

If you will opt to run the “running-config.sh” from the hotfortech project on your router, you will find that it will currently install for you: The anti-ads-pack, the Opkg geek-init script, as well as things such as the full GNU “ls”, “less”, “BASH” and more.

如果您选择在路由器上的hotfortech项目中运行“ running-config.sh”,则会发现它目前已为您安装: anti-ads-packOpkg geek-init脚本以及诸如完整的GNU“ ls”,“较少”,“ BASH”等等之类的东西。

/jffs/svn/hotfortech-dd-wrt/running-conf.sh

/jffs/svn/hotfortech-dd-wrt/running-conf.sh

More features are pending and will be added in the future.

更多功能正在等待中,并将在将来添加。



System administrators will code their way out of coding.

系统管理员将采用他们自己的编码方式。

翻译自: https://www.howtogeek.com/66731/version-tracking-with-subversion-svn-for-beginners/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值