1、SVN 基础知识

1.1、常用图标含义

原则: 先更新, 后提交,出现冲突先解决冲突

图标 图标样式 描述
问号 Unversioned, 未在版本控制中
黄色的小瓶子 项目的版本和服务器里面项目的版本一致
灰色的勾 锁定文件
黑星 本地修改未提交的文件
黑右箭头 本地修改过文件
蓝左箭头 服务器端修改过文件
黑右加箭头 本地比服务器多出的文件
蓝右加箭头 服务器端比本地多出的文件
黑右减箭头 本地已删除, 服务器未删除
蓝左减箭头 服务器已删除, 本地未删除
红双向箭头 服务器中修改过, 本地也修改过(出现冲突)的
未更新数量
未提交数量
冲突数量

具体例子:

1.2、系统文件的Tortoise SVN含义

图标 描述
一个新检出的工作复本使用绿色的勾做重载。表示Subversion状态 正常。
在开始编辑一个文件后,状态就变成 已修改,而图标重载变成了红色感叹号。通过这种方式,可以很容易地看出那些文件从你上次更新工作复本后被修改过,需要提交。
如果在提交的过程中出现了 冲突 图标变成黄色感叹号。
如果你个一个文件设置了 svn:needs-lock属性, Subversion 会让此文件只读,直到你获得文件锁。
只读文件具有这个重载图标来表示你必须在编辑之前先得到一个锁
如果你拥有一个文件的锁,并且Subversion状态时 正常 ,这个重载图标就提醒你如果不使用该文件的话应该释放锁,允许别人提交对该文件的修改。
这个图标表示当前文件夹下的某些文件或文件夹已经被计划从版本控制中 删除,或是该文件夹下某个受控的文件丢失了。
该图标告诉你有一个文件或是目录已经被计划加入版本控制。

1.3、Eclipse 下的 SVN 含义

1.3.1) 项目视图(The Package Explorer view)

图标 描述 英文描述
已忽略版本控制的文件。可以通过Window → Preferences → Team → Ignored Resources.来忽略文件。 A file ignored by version control. You can control what resources will be ignored by going to Window → Preferences → Team → Ignored Resources.
未纳入版本控制的文件,一般是新增,尚未提交的文件 A file not under version control. These are typically new files that you have not committed to the repository yet.
本地重命名或移动到其它目录的文件。 A versioned file that needs to be added to the remote repository. These are typically files you have either renamed, or moved to a different directory.
本地删除的目录 A deleted folder. These are folders that you have deleted locally without yet committing the changes to the repository. Note that files are usually removed from the view when they’re deleted locally, so they are normally not seen with this icon.
没有任何改动的文件。 A file with no local changes.
发生改动,尚未提交的文件。 A file with local, uncommitted changes.
处于锁定状态的文件 A locked file.
有冲突没有解决,就更新或提交的文件。 A conflicted file. These are typically files that had a commit/update conflict that you marked to resolve later.
有目录树冲突的文件。一般在最近一次更新后,资源库上的文件被移动、删除或重命名。 A file that has a tree conflict. These are typically files that have local changes, but have since been moved, removed, or renamed in the repository since the last local copy update.
引用外部项目的文件,不能提交到本项目的资源库里。 A file that is external to the project. Linked external files cannot be committed to the repository.
有分支版本的文件。这些文件属于另外一个不同的工作目录而不是属于本地的父目录 A file that has been switched. These are files which belongs to a different working copy than their local parent directory.

1.3.2 迁出视图(Outgoing view)

图标 描述 英文描述
本地有更改的文件 A file whose contents have been modified and will be committed to the repository.
本地新增的文件 A file that will be newly added to the repository. This may coincide with a file removal in cases where a file is moved or renamed.
本地删除的文件。 A file that will be removed from the repository. This may coincide with a file addition in cases where a file is moved or renamed.
本地文件属性发生变化了的文件。比如在合并代码时候,提交代码会出现代码合并。 A file with property changes, in the Commit dialog. On the Synchronize tab, property changes are currently reflected as a normal file modification() .
  • 1.3.3 迁入视图(Incoming view)

图标 描述 英文描述
需要更新的文件 A file that has content changes committed to the repository that will be applied to the local copy.
需要迁入的新增文件。 A new file that will be added to the local copy from the repository. Like the outgoing file addition, this may be the result of a move or rename.
资源库中删除了的文件。 A file that will be removed from the local copy because it has been removed from the repository. Like the outgoing file removal, this may be the result of a move or rename.

1.3.4 冲突视图(Conflict view)

图标 描述 英文描述
资源库和本地同时有修改的文件。 A file that has been changed in both the local copy and repository independently, causing a need for conflict resolution. Fixing this condition involves opening up the conflict view or forcibly overwriting changes locally or remotely.
远程资源库上已经被重命名或移动、删除的文件。 A file that has a tree conflict. This can occur when there are new changes to a file on one end (either local or remote), and the file is moved, removed, or renamed on the other.

1.3.5 “与资源库同步”选项打开的界面上的一些按钮 Others

Finally, the Synchronize with Repository option opens the Synchronize tab ( ) with the following buttons:

图标 描述 英文描述
同步选中的文件,下拉箭头切换不同的远程目录。 Synchronizes the local copy with the currently selected repository when clicked. Selecting from the drop-down allows switching between different remote code bases.
只显示需要迁入的文件。 Shows only incoming changes (remote → local).
只显示需要提交的文件 Shows only outgoing changes (local → remote).
同时显示需要更新或提交文件。 Shows both incoming and outgoing changes (remote ↔ local).
只显示有冲突的文件。 Shows conflicting changes.
更新全部文件。 Updates all local resources with incoming changes after prompt.
提交全部文件。 Brings up the commit dialog to commit all outgoing changes.

2、SVN代码提交规范

2.1 不需要提交的代码(忽略代码)

以下代码不需要提交,请右键添加到忽略,然后在把整个项目提交(这个一般在新建maven项目时候出现)。

要忽略的目录

添加到svn 忽略

或者统一忽略 **

在eclipse工具栏上window->Prefernces->Team->Ignored Resource
增加*/.setting/*  */target/*  .classpath

2.2 提交的代码请填写相关注释

提交的代码请填写相关备注,这样对找回之前版本能很快定位,其他人员更新你代码也可以了解你提交解决办法。
对于合并版本很重要,知道合并到那个位置。

2.3 提交或更新代码的操作

请一定要用“与资源库同步”的方式,禁止采用 更新

2.4 更新代码出现冲突

请合并代码,解决代码冲突

解决办法一

冲突情况1:服务器代码和自己代码改动的地方相同

    该情况比较复杂,建议将自己的代码备份一份到本地,然后直接将服务器代码更新下来,然后在新的代码上修改自己的逻辑。出现该情况如果不清楚如何修改请与上传的人沟通
就比如说你和上一个上传代码的人修改了同一个地方但是在他上传的时候你没有更新,导致你提交的时候发现你和他改动的地方为一样。截图打个比方:

上面的例子应该能看懂左侧代码为自己的代码观察发现被自己注释掉了所以可以对比代码是否是最新,如果本地代码不是最新可以将右侧代码复制到右侧保存,最后右击冲突文件点击标记为合并即可。
注:以上只是打个比方还有其他冲突情况没有列举可以根据代码逻辑自行合并。

冲突情况2:服务器代码和自己代码改动的地方不同

    该情况比较常见,就是你跟别的开发者都在更改同一个文件,但是由于开发任务是分开的,所以更改的地方是不同的,解决办法如下。
1、双击冲突文件进入比较视图
2、找到服务器上新增的但本地没有的代码块,选中此代码块,点击右上角的按钮(如下图箭头指向的按钮)将服务器代码复制到本地(其他地方也同此操作),如果点击按钮没用,则关闭比较视图重新打开

复制成功后本地左侧代码为最新代码

保存后发现右侧新增代码消失。
3.如果显示有冲突(你没有改动过该代码哦)将所有服务器上新增的代码复制到本地文件后,右键冲突文件选择标记为合并即可,此时该文件就会消失在Synchronize视图下,并且该文件的代码已经成功将本地代码和远程代码合并到一起.

冲突情况3: svn提交上次cleanup 中断后导致的死循环


解决方法:清空svn的队列

解决办法二【不建议采用】

不建议采用该办法,该方式是未正确更新代码产生,实际应该避免出现。


1、如果出现冲突会多出三个文件,分别是:“.mine”“r(xxx+1)”“r(xxx)”其中xxx为版本号。
“.mine”是我要提交的文件,
“.r(xxx)”是我是在这个版本文件基础上修改后产生冲突的。
“r(xxx+1)”是目前svn服务器最新版本的内容是这样。

2、我们通过手动处理源文件,修改得到自己真实想要上传到svn的文件后。右击Team->标记为解决(Mark as Merged)。默认选择第一个“标记为冲突解决”,点击OK。刚才的三个文件将消失,剩下自己的源文件。


3、编辑源文件为自己真正想要到svn服务器上的最新版本文件。右击Team->提交,冲突解决

2.5 删除或者忽略文件提交不上(或者过旧)

出现超时或版本过旧,请按以下操作:
1、 Update to Version
2、 Refresh/Cleanup

2.6 版本规范


1. 严禁使用其他人的账号提交代码。

2. 准备阶段
a) 本机是否编译通过?
本机不能编译通过,不允许做提交操作。
b) 这些代码自己是否能够看明白?
提交的代码必须是原子性的,如完成了某个功能,修复了某个bug,做了某个页面调整等。
对于只是自己使用的代码,比如private方法,可以阶段性完成即提交,但最起码自己看得明白,不是垃圾代码。

3. 先更新、合并代码
每一次要提交前,先查看要提交的文件在SVN服务器上是否有修改。
如eclipse就是右键点击要提交的目录,选择Subversion显示更改。
禁止不更新合并就直接提交,出现代码冲突

4. 更新合并后,是否编译通过?
如编译不通过,则调整代码或更新编译依赖的其它的文件。

5. 禁止提交的文件
a) 本地IDE自动生成的文件,如.classpath、.settings
b) 本地测试的文件,如uploads的图片、附件等。(这些目录应该设置为svn ignore)
c) 配置文件的本地化修改。比如app.properties,使用了本机的数据库。

6. 提交代码——逐个文件提交!
除了下面这些例外,其它的文件请逐个提交:
a) 第三方组件的新增或者升级。(注:我方做个性化重构时需要逐一提交)
b) 某个目录的文件全部是新增的。
c) 样式设计和设计图片。

7. 每次提交必须书写明晰的标注
逐个文件提交,单独写标注,记录调整历史,方便其他开发人员更新和理解。
a) 描述本次提交的文件变更内容。
b) 如果修复了禅道的bug,请附上禅道的bug 编号。
(注:需要配置禅道和SVN的整合)
c) 如果新增任务了,请附上禅道的task 编号。

8. 发布版本周期要短——管理员打Tag
这要求项目经理将每个小版本的待开发功能控制在一定数量内,保证周期要短,这样才可以经常打tag发布版本。
步子要小,这样项目才更加可控,每个版本的稳定性才更能保证。

文档更新时间: 2023-01-31 11:28   作者:hugh