将你的修改提交到版本库

Posted on Posted in 6.日常使用指南

将你的修改提交到版本库

将你对工作副本的修改发送给版本库,称为提交修改。但在你提交之前要确保你的工作副本是最新的。你可以直接使用TortoiseSVN → 更新,或者,你可以先使用TortoiseSVN → 检查修改看看哪些文件在本地或是服务器上已经有了改动。

提交对话框

如果你的工作副本是最新的,并且没有冲突,你就已经为提交做好准备了,选择你要提交的文件和/或文件夹,然后TortoiseSVN → 提交….

图 5.8. 提交对话框

提交对话框

提交对话框将显示每个被改动过的文件,包括新增的、删除的和未受控的文件。如果你不想改动被提交,只要将该文件的复选框的勾去掉就可以了。如果你要加入未受控的文件,只要勾选该文件把它加入提交列表就可以了。

那些被切换(switched)到不同版本库路径的项也用(s)标记来表示。当工作在分支上的时候你可能切换到某处,然后忘记切换回主干。这是你的警告信号!

提交文件还是文件夹?

当你提交文件时,提交对话框只显示你所提中的文件。当你提交文件夹中,提交对话框将自动选择有改动的文件。如果你忘记了你建立的一个新文件,提交文件夹将使你可以找到它。提交一个文件夹并不意味着每个文件都被标识为修改过的,它仅仅是通过帮你多做些事从而让你的生活更滋润一点。

如果你修改的文件是使用了svn:externals从别的版本库中包含进来的,那么这些改动不会被自动提交。在文件列表下方的警告符号会告诉你是否出现了这种状况,工具提示(tooltip)提示了外部文件必须要分开提交。

在提交对话框中有很多未受控的文件

如果你认为提交对话框显示了太多的未受版本控制的文件(如编译器产生的文件或是编辑器的备份文件),有几种方法可以处理这种情况。你可以:

  • 将文件(或是通配符扩展)加入到设置页的排除列表中。这对每个工作副本都起作用。

  • 使用TortoiseSVN → 加入忽略列表,将文件加入svn:ignore列表。 这只对你设置了svn:ignore属性的路径有效。使用SVN属性对话框,你可以改变一个目录的svn:ignore属性。

参考 “忽略文件和目录”一节 获得更多的信息。

在提交对话框中双击任何修改过的文件,将运行外部 diff 工具显示你做的改动。上下文菜单将给你更多的选项,请看屏幕截图。你可以从这里将文件拖动到另一个应用程序中,如文本编辑器或 IDE。

You can select or deselect items by clicking on the checkbox to the left of the item. For directories you can use Shift-select to make the action recursive.

在底部面板中显示的列是可定制的。如果你右击任何一列的头部,你就会看到一个上下文菜单,允许你选择哪一列要显示。还可以在鼠标移动到列边界时通过拖动手把来改变列的宽度。这些定制的内容都会被保留下来,下一次你会见到相同的列。

缺省情况下,当你成功提交修改后,你在这些文件上持有的锁会被自动释放。如果你需要保留锁,请确认选中检查框保留锁。此检查框的缺省状态从 Subversion 配置文件的 no_unlock 选项获取。参考 “常规设置”一节 以获得更多关于编辑 Subversion 配置文件的信息。

拖放

你可以将文件从别的地方拖动到提交对话框,只要工作副本是由同一版本库中检出就可以了。比如,你有一个很大的工作副本,要开好几个资源管理器窗口来查看层次中不同的文件夹。如果你要避免从顶级文件夹提交(冗长而缓慢的文件夹改动检查),你可以打开一个文件夹的提交对话框,然后将别的窗口中的项拖进去,可样就可以一次提交它们了。

你可以将未版本控制的文件拖到工作副本提交对话框中,它们就会被自动增加。

修复外部改名

有时候文件不是用Subversion改名,于是它们在文件列表中作为丢失和未版本控制的文件出现。为了避免丢失历史,你需要通知Subversion。简单的选择老名称(丢失)和新名称(未版本控制),然后使用右键菜单 → 修复移动来指明这两个文件是改名关系。

修改列表

The
 commit dialog supports Subversion's changelist feature to help with
 grouping related files together. Find out about this feature in “修改列表”一节.

Excluding Items from the Commit List

Sometimes
 you have versioned files that change frequently but that you really
 don't want to commit. Sometimes this indicates a flaw in your build
 process – why are those files versioned? should you be using template
 files? But occasionally it is inevitable. A classic reason is that your
 IDE changes a timestamp in the project file every time you build. The
 project file has to be versioned as it includes all the build settings,
 but it doesn't need to be committed just because the timestamp
changed.

To help out in awkward cases like this, we have reserved a changelist called ignore-on-commit.
 Any file added to this changelist will automatically be unchecked in
 the commit dialog. You can still commit changes, but you have to select
 it manually in the commit dialog.

提交日志信息

确保输入描述你所提交的修改内容的日志信息。这可以帮你回顾做了什么,什么时候做的。信息的内容可长可短,许多项目规定了要包含的内容、使用的语言甚至是严格的格式。

你可以使用与电子邮件相似的约定,简单格式化日志消息。如果对文本采用这些样式,使用*文本*表示粗体,_文本_表示下划线,^文本^表示斜体。

图 5.9. 提交对话框的拼写检查器

提交对话框的拼写检查器

TortoiseSVN包含了一个拼写检查器帮助你正确地书写日志信息。对任何错误拼写的词都高亮显示。使用右键菜单可以获得修改建议。当然它不会知道所有的技术术语,所以有时一些拼写正确的词会被当作错误。但不用担心,你可以使用右键菜单将它们加入你的个人字典中。

The
 log message window also includes a filename and function
 auto-completion facility. This uses regular expressions to extract
class  and function names from the (text) files you are committing, as
well as  the filenames themselves. If a word you are typing matches
anything in  the list (after you have typed at least 3 characters, or
pressed Ctrl+Space),  a drop-down appears allowing you
to select the full name. The regular  expressions supplied with
TortoiseSVN are held in the TortoiseSVN  installation bin folder. You can also define your own regexes and store them in %APPDATA%\TortoiseSVN\autolist.txt.
 Of course your private autolist will not be overwritten when you
update  your installation of TortoiseSVN. If you are unfamiliar with
regular  expressions, take a look at the introduction at http://en.wikipedia.org/wiki/Regular_expression, and the online documentation and tutorial at http://www.regular-expressions.info/.

You
can re-use previously entered log messages. Just click on Recent
messages  to view a list of the last few messages you entered for this
working  copy. The number of stored messages can be customized in the
TortoiseSVN  settings dialog.

You can clear all stored commit
messages from the Saved data page of TortoiseSVN's settings, or you can
clear individual messages from within the Recent messages dialog using
the Delete key.

指定文件夹属性

有几个特殊的文件夹属性可用于帮助我们得到更多的对提交日志信息的格式以及拼写检查模块的控制。参考“项目设置”一节以了解详情。

与缺陷跟踪工具集成

If
you have activated the bug tracking system, you can set one or more
Issues in the Bug-ID / Issue-Nr:  text box. Multiple issues should be
comma separated. Alternatively, if  you are using regex-based bug
tracking support, just add your issue  references as part of the log
message. Learn more in “与 BUG 跟踪系统/问题跟踪集成”一节.

提交进程

在按下OK之后,会出现一个对话框显示提交的进度。

图 5.10. 显示提交进度的进度对话框

显示提交进度的进度对话框

进度对话框使用颜色代码来高亮显示不同的提交行为。

  • 蓝色

  • 提交一个修改。

  • 紫色

  • 提交一个新增项。

  • 深红

  • 提交一个删除或是替换。

  • 黑色

  • 所有其他项。

这是默认的配色方案,但你可以通过设置对话框来定制这些颜色。参考“TortoiseSVN 颜色设置”一节获得详情。