`

SVN Useful Commands

阅读更多

Useful Commands

Here are some examples of revision keywords in action. Don't worry if the commands don't make sense yet; we'll be explaining these commands as we go through the chapter:

$ svn diff --revision PREV:COMMITTED foo.c # shows the last change committed to foo.c

$ svn log --revision HEAD # shows log message for the latest repository commit

$ svn diff --revision HEAD # compares your working file (with local changes) to the latest version # in the repository

$ svn diff --revision BASE:HEAD foo.c # compares your "pristine" foo.c (no local changes) with the # latest version in the repository

$ svn log --revision BASE:HEAD # shows all commit logs since you last updated

$ svn update --revision PREV foo.c # rewinds the last change on foo.c # (foo.c's working revision is decreased)

$ svn info | grep URL

$ svn log -v -r9238 {Path} # to read about the exact changeset which fixed the bug at 9238

$ svn diff -r9237:9238 {path} # to see the patch itself

 

 

Undo Changes

  • Working Repository
    • svn revert --recursively
  • Undelete a file
    • get the path@revision by svn log -v
    • svn copy --revision 807 http://svn.example.com/repos/calc/trunk/real.c ./real.c
    • svn commit with log message "Resurrected real.c from revision 807, /calc/trunk/real.c."
    • or use svn merge to a single file
  • Undo a changeset in Repository on Server
Suppose you're working away happily on a working copy of /calc/trunk, and you discover that the change made way back in revision 303, which changed integer.c, is completely wrong. It never should have been committed. You can use svn merge to “undo” the change in your working copy, and then commit the local modification to the repository. All you need to do is to specify a reverse difference:

$ svn merge -r 303:302 http://svn.example.com/repos/calc/trunk U integer.c

$ svn status M integer.c

$ svn diff … # verify that the change is removed …

$ svn commit -m "Undoing change committed in r303." Sending integer.c Transmitting file data . Committed revision 350.

 

Branch

 

  • Creating a Branch
    svn copy http://svn.example.com/sample/trunk \
                  http://svn.example.com/sample/branches/{larryli}_branch  \
          -m "Creating a private branch of /calc/trunk. {Tracking Number}"
    

 

  • Creating a Working Copy of a Branch
    1. Check Out a branch
    2. Switch to a branch
      • switch command transforms an existing working copy into a different branch
      • svn switch command also takes a --revision (-r) option, so you need not always move your working copy to the “tip” of the branch.
      • switch command transforms an directory under existing working copy into a different branch
      • A superset of svn update

 

Merge

  • Sample Merge Commands
    1. $ svn merge http://svn.example.com/repos/branch1@150 http://svn.example.com/repos/branch2@212 my-working-copy
      • The first syntax lays out all three arguments explicitly, naming each tree in the form URL@REV and naming the working copy target
    2. $ svn merge -r 100:200 http://svn.example.com/repos/trunk my-working-copy
      • second syntax can be used as a shorthand for situations when you're comparing two different revisions of the same URL.
    3. $ svn merge -r 100:200 http://svn.example.com/repos/trunk
      • The last syntax shows how the working-copy argument is optional; if omitted, it defaults to the current directory.
  • Merge = Diff and Apply
  • Assume that your working copy has no local edits. When you svn update to a particular revision, the changes sent by the server will always apply “cleanly” to your working copy. The server produces the delta by comparing two trees: a virtual snapshot of your working copy, and the revision tree you're interested in. Because the left-hand side of the comparison is exactly equal to what you already have, the delta is guaranteed to correctly convert your working copy into the right-hand tree.
  • Undo
    1. svn revert --recursive
    2. delete any unversioned files or directories left behind after the revert ( using svn status to check the unversioned the files)

 

 

Best Practice

  1. Tracking Merges Manually
    • As there is no way for svn knowing the local changes done by svn merge and local modification by editting, so we need write down the specific revision number (or range of revisions) that are being merged into your branch.
  2. Previewing Merges
    • Check if the last merge happened or not from the svn log information.
    • In case the svn merge will mingle the changes to our local modification together so as to no way to revert. Please do one of the below two commands before merging.
      1. To check the differences in detail, run diff command with the same arguments you would run svn merge This way we can see what will update to our code.
      2. To get a rough information, run merge with the option --dry-run.
  3. Noticing or Ignoring Ancestry
    • Diff: ignore the ancestor by default. --notice-ancestry
    • Merge: sensitive to ancestry by default. --ignore-ancestry

 

Merging a whole Branch to Trunk

  • Get the BASE revision of the branch: svn log --verbose --stop-on-copy {branch_name}
  • Go to the trunk cd {application}/trunk
  • Get the latest repository revision and refresh local trunk so we can get the HEAD revision: svn update .
  • Merge the difference. svn merge -r branch_base:repository_HEAD http://svn.example.com/.../webapps/SampleApps/my-sample-branch
  • Check the local status: svn status
  • examine the diffs, compile, test, etc...
  • Commit the change with the specified the log message: "Merged my-sample-branch changes rBASE:HEAD into the trunk."
  • please check http://svnbook.red-bean.com/en/1.0/ch04s04.html#svn-ch-4-sect-4.1 for more details.

 

Ignore files

  • Some files created by an IDE, such as Eclipse are quite annoying. We need to take care of not checking them into svn. Below is my way to ignore those files.
    1. The files wanna to be ignored
      /home/larryli/svn/offline/webapps/TimeTrackerII>svn status .
      ?      .project
      ?      .classpath
      ?      .mymetadata
      ?      .myeclipse
      ?      META-INF/MANIFEST.MF
      ?      WEB-INF/classes
      /home/larryli/svn/offline/webapps/TimeTrackerII>ls -ltr
      
    2. Edit the file /home/larryli/.subversion>vi /home/larryli/.subversion/config
      # global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store
      global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store .project .classpath .mymetadata .myeclipse MANIFEST.MF classes
      
    3. Go back and check. It works ok.
      /home/larryli>cd /home/larryli/svn/offline/webapps/TimeTrackerII
      /home/larryli/svn/offline/webapps/TimeTrackerII>svn status .
      /home/larryli/svn/offline/webapps/TimeTrackerII>
      
  • Online Reference
    1. http://svnbook.red-bean.com/en/1.1/ch07s02.html
    2. http://svnbook.red-bean.com/en/1.1/ch07.html#svn-ch-7-sect-1.3.2

分享到:
评论

相关推荐

    svn1.14.1、svn1.14.2

    svn1.14.1、svn1.14.2

    svn-win32-1.7.2.zip (win32svn) [SVN 绿色版]

    将文件解压缩到 C:\ 下,将解压缩后的 svn-win32-1.7.2 文件夹名改为 svn,然后将 C:\svn\bin 加入到系统的 PATH 环境变量中,即可开始使用。 将 svnserve.exe 设置为系统服务: sc create svn binpath= "C:\svn\...

    svn服务用svnsync命令双机热备

    ### SVN服务用svnsync命令实现双机热备 #### 概述 在软件开发过程中,版本控制系统(Version Control System, VCS)是必不可少的工具之一。Subversion(SVN)作为一款广受欢迎的集中式版本控制系统,在企业级项目...

    清楚svn目录下生成的.svn文件夹

    在使用Subversion(SVN)版本控制系统管理代码时,`.svn`文件夹是SVN用于存储元数据的地方,包括版本信息、工作副本配置等。这些文件夹对于SVN的正常运行至关重要,但有时它们可能会占用大量的磁盘空间,或者在不...

    获取svn最新版本号示例 以及svn常用命令

    在软件开发过程中,版本控制系统是不可或缺的工具,其中Subversion(简称svn)是广泛应用的一种集中式版本控制系统。本文将深入探讨如何获取svn的最新版本号,并介绍一些常用的svn命令。 首先,获取svn的最新版本号...

    svn插件myeclipse+svn插件

    【标题】:“svn插件myeclipse+svn插件” 【描述】:“svn 插件 myeclipse 插件文件+安装方法在压缩包内” 本文将深入探讨如何在MyEclipse集成开发环境中安装和使用Subversion(SVN)插件,以便更有效地进行版本...

    如何去掉svn标记

    在软件开发过程中,版本控制系统扮演着至关重要的角色,其中Subversion(简称SVN)作为一款开源的集中式版本控制系统,被广泛应用于项目管理之中。然而,在使用SVN的过程中,用户可能会遇到一个常见的问题:如何去除...

    SVN中文手册 SVN中文手册

    SVN svn SVN中文手册 SVN资料 svn配置SVN svn SVN中文手册 SVN资料 svn配置SVN svn SVN中文手册 SVN资料 svn配置SVN svn SVN中文手册 SVN资料 svn配置SVN svn SVN中文手册 SVN资料 svn配置SVN svn SVN中文手册 SVN...

    VS2022 SVN 插件

    **Visual Studio 2022 SVN 插件详解** 在软件开发过程中,版本控制是至关重要的环节,它帮助团队协作并跟踪代码的变化。Subversion(简称SVN)是一款流行的开源版本控制系统,而AnkhSVN则是一个针对Microsoft ...

    svn绿色windows版本,客户端,支持IntelliJ IDEA配置svn客户端环境

    SVN(Subversion)是一种广泛使用的版本控制系统,用于管理文件和目录的历史版本,便于团队协作和项目管理。在Windows平台上,有许多SVN客户端可供选择,其中SlikSVN是一款流行的轻量级绿色版本,尤其适合那些希望...

    清理SVN、断开SVN连接,工具

    在IT行业中,版本控制系统是开发团队协作的重要工具之一,Subversion(简称SVN)就是其中广泛应用的一款。SVN能够帮助开发者追踪代码的变化,合并不同人的修改,并管理项目的多个版本。然而,有时候我们可能需要断开...

    svn清理sqlite3

    在IT行业中,版本控制系统是开发团队协作的重要工具,Subversion(简称svn)就是其中的一款广泛应用的开源版本控制系统。本文将详细讲解如何解决“svn无法清理、上传、下载”的问题,以及涉及的SQLite3数据库相关...

    SVN中文教程 SVN简明教程 SVN学习笔记

    SVN,全称为Subversion,是一款广泛应用于软件开发领域的版本控制系统。它允许团队协作开发,管理项目中的文件和目录,并追踪每一次更改,确保代码的安全性和可追溯性。本教程将深入探讨SVN的基础知识,包括安装配置...

    svn账号密码找回,本地svn账户查看

    在IT行业中,版本控制系统是开发团队协作的重要工具,其中Subversion(简称svn)是一种广泛应用的集中式版本控制系统。本文将详细讲解如何进行“svn账号密码找回”以及“本地svn账户查看”的操作。 首先,让我们来...

    RapidSVN:轻量级、可视化SVN客户端RapidSVN-0.13.0.8249-PortableSoft

    RapidSVN是一款轻量级且用户友好的可视化Subversion(SVN)客户端,专为开发者和团队协作设计。Subversion是一种版本控制系统,用于管理软件项目中的文件和目录的更改历史,使得多人协同开发变得更加高效和有序。...

    .svn删除软件

    在IT行业中,版本控制系统是开发团队协作的重要工具,其中Subversion(简称SVN)是一种广泛应用的集中式版本控制系统。`.svn`文件是Subversion在本地工作副本中存储元数据的特殊文件,它记录了文件和目录的状态信息...

    svn1.8.3免安装版

    【标题】"svn1.8.3免安装版"指的是Subversion(SVN)版本控制系统的一个特定版本,1.8.3,它不需要通过传统的安装程序进行安装,而是可以直接使用解压缩的方式运行。Subversion是一种开源的版本控制系统,用于管理...

    SVNMANAGER SVN 代码管理 LINUX SVN管理

    【SVNMANAGER SVN 代码管理 LINUX SVN管理】 在软件开发过程中,版本控制是至关重要的一个环节,它能帮助团队协同工作,跟踪代码修改历史,以及有效地管理代码库。Subversion(简称SVN)就是这样一款广泛应用的版本...

    myeclipse2017SVN插件

    【Myeclipse2017 SVN插件】是一款专为Myeclipse 2017集成开发环境设计的版本控制系统工具,它使得开发者能够在Myeclipse中直接进行SVN(Subversion)的操作,如代码的版本控制、提交、更新、解决冲突等。SVN是分布式...

    svn TortoiseSVN 1.14.5 (64-bit)

    svn TortoiseSVN 1.14.5 (64-bit) svn客户端svn TortoiseSVN 1.14.5 (64-bit) svn客户端svn TortoiseSVN 1.14.5 (64-bit) svn客户端svn TortoiseSVN 1.14.5 (64-bit) svn客户端svn TortoiseSVN 1.14.5 (64-bit) svn...

Global site tag (gtag.js) - Google Analytics