SVN – 查看更改
SVN – 查看更改
Jerry已将array.c文件添加到存储库中。Tom还检查了最新的代码并开始工作。
[tom@CentOS ~]$ svn co http://svn.server.com/svn/project_repo --username=tom
以上命令将产生以下结果。
A project_repo/trunk A project_repo/trunk/array.c A project_repo/branches A project_repo/tags Checked out revision 2.
但是,他发现有人已经添加了代码。所以他很好奇是谁做的,他使用以下命令检查日志消息以查看更多详细信息:
[tom@CentOS trunk]$ svn log
以上命令将产生以下结果。
------------------------------------------------------------------------ r2 | jerry | 2013-08-17 20:40:43 +0530 (Sat, 17 Aug 2013) | 1 line Initial commit ------------------------------------------------------------------------ r1 | jerry | 2013-08-04 23:43:08 +0530 (Sun, 04 Aug 2013) | 1 line Create trunk, branches, tags directory structure ------------------------------------------------------------------------
当Tom观察Jerry 的代码时,他立即注意到其中的一个错误。Jerry 没有检查数组溢出,这可能会导致严重的问题。所以汤姆决定解决这个问题。修改后,array.c会是这个样子。
#include <stdio.h>
#define MAX 16
int main(void)
{
int i, n, arr[MAX];
printf("Enter the total number of elements: ");
scanf("%d", &n);
/* handle array overflow condition */
if (n > MAX) {
fprintf(stderr, "Number of elements must be less than %d\n", MAX);
return 1;
}
printf("Enter the elements\n");
for (i = 0; i < n; ++i)
scanf("%d", &arr[i]);
printf("Array has following elements\n");
for (i = 0; i < n; ++i)
printf("|%d| ", arr[i]);
printf("\n");
return 0;
}
Tom想使用 status 操作来查看挂起的更改列表。
[tom@CentOS trunk]$ svn status M array.c
array.c文件被修改,这就是为什么 Subversion在文件名前显示M字母。接下来,Tom编译并测试他的代码,它运行良好。在提交更改之前,他想通过审查他所做的更改来仔细检查它。
[tom@CentOS trunk]$ svn diff
Index: array.c
===================================================================
--- array.c (revision 2)
+++ array.c (working copy)
@@ -9,6 +9,11 @@
printf("Enter the total number of elements: ");
scanf("%d", &n);
+ if (n > MAX) {
+ fprintf(stderr, "Number of elements must be less than %d\n", MAX);
+ return 1;
+ }
+
printf("Enter the elements\n");
for (i = 0; i < n; ++i)
Tom在array.c文件中添加了几行,这就是 Subversion在新行之前显示+符号的原因。现在他已准备好提交他的更改。
[tom@CentOS trunk]$ svn commit -m "Fix array overflow problem"
上述命令将产生以下结果。
Sending trunk/array.c Transmitting file data . Committed revision 3.
Tom 的更改已成功提交到存储库。