开发中项目的版本管理和svn使用(下)

时间:2021-02-11 08:54:40

上篇主要介绍了版本管理,下篇会写一下svn工具的使用,会覆盖svn的基本使用方法,重点在分支管理上。

svn的基本使用方法

相信很多程序员每天到公司的第一件事情就是打开编译器同步代码,把最新的代码下载到本地;每天的最后一件事情也很有可能是向svn/git提交最新代码关电脑回家。暂时没有使用过git,整理一下svn使用的基本方法吧。

在eclipse上安装svn插件

公司自行开发的前端开发插件不支持在Idea上使用,所以全公司的开发工具几乎都是eclipse……….(这是一句吐槽)
首先安装eclipse,在官网上下载最新安装包安装一路next即可。然后是安装插件,有两种方法。其一是使用eclipse自带的功能安装:help—>install new software,在打开的新窗口里填上name:subclipse,url:http://subclipse.tigris.org/update_1.10.x;然后点击add,都选上,一路next即可。但是由于网路环境各种原因,这个安装方式失败的几率是很高的….第二种方式就是直接从url:http://subclipse.tigris.org/servlets/ProjectDocumentList?folderID=2240 下载,然后解压,将压缩包features和plugins目录中的文件分别复制到Eclipse安装目录的features和plugins中,重启即可。

svn更新和提交

这是两个最基本动作。只要记得在更新和提交之前先同步代码,确认有没有冲突即可。

svn冲突代码解决

新手很容易因为代码冲突丢失代码,我也干过这事儿…..同理,请慎重使用”更新并覆盖本地代码“选项,因为这么一操作,本地修改也会被覆盖掉,消失得无影无踪。
冲突代码产生的原因是多人同时修改同一个文件,并且提交。一旦产生代码冲突是不能直接提交代码的,必须先解决冲突才能正常提交。
解决方式是这样的:对于有代码冲突的文件,选择更新操作,此时本地会出现这么几个文件:

  • a.java 待处理的文件
  • a.java.mine 本地修改的文件
  • a.java.r(xxx+1) 服务器最新版本
  • a.java.r(xxx) 本地修改的基础版本(服务器取下的版本)

这时候手动处理“a.Java”,得到一个合并的最新版本,然后右击Team->标记为解决。默认选择第一个“标记为冲突解决”,点击OK。刚才的三个文件将消失,剩下自己的源文件。这时候就可以提交了

svn分支的拉取和合并

开发中版本管理是必不可少的,每多一个支线就新开一个分支,每当一个支线完成开发就合并一个分支。

svn代码建立分支

在eclipse中选择项目,右击Team–>Branch/Tag,在弹出窗口的“到 Url”填入新分支的url,选择ok即可。
开发中项目的版本管理和svn使用(下)

svn代码代码合并(merge)

merge的选项

开发中项目的版本管理和svn使用(下)

代码合并相对于建立分支稍微复杂一点,你从哪个项目上点击这个目录,那个项目就是目标,而填入的url就是被merge的分支。假如我们在trunk上点击merge,填入branches上的一个url,那么上面菜单对应的意思就是:

  • 将branches的部分修改合并到trunk上
  • 将branches的全部修改合并到trunk上
  • 将trunk上的修改合并到branches。
  • 合并2个分支到主干,需要填入两个branches的地址,当然也可以填一个branches和trunk
  • 从branches到trunk,手动锁定部分不需要合并的代码
  • 从branches到trunk,解锁部分已经锁定的代码
    英文不是很好,还是贴上每个选项自带的英文解释,有心的可以再看看

  • Use this method to catch-up a feature branch with the changes in trunk or another branch. You can merge a specific set of revisions or all eligible revisions

  • Use this method to merge the changes in feature branch to trunk or the location the branch was created from. To use this method the working copy must not hava any local modifications.It must be at a revision of the working copy must be greater than or equal to the last recision the branch was synchronized to
  • Use this method to merge the rivisions associated with one or more CollabNet artifacts. Typically this option would be used to backport fixes to a release branch or similiar scenarios where all of the changes associated with an artifact need to be merged from one location to another
  • Use this method to merge the differences between two URL and revision pair into the current location. This could be used as an alternative to the reintegrate merge scenario when you want to control the specific path and revisions that are being compared for the merge input
  • use this method to block a revision or range of revisions from being merged into this location. For example,you might want to do this if the changes in the branch have already been manually applied to this location or you do not intend to ever merge the changes form the branch into this location
  • Use this method to unlock a revison or range of revision that have previously been blocked from this location.You might also use this option to manually remove the record of some revisions having been merged so that they can be merged again.

那么我们一般的使用方式就是从branches合并代码到trunk,自己对应选择上面的选项就可以了。

merge的两个常见错误

  1. no uncommited modified :表示当前版本还有没有提交的文件,如果不需要提交就选择revert.需要提交就先提交代码,再merge就可以了
  2. working copy at a single version:表示当前目录没有从SVN服务器更新最新的版本。update下后在操作就行了。