Svn 简明教程
SVN - Update Process
Jerry 已提交第一个版本的代码。但他认为他应该编写两个函数来接受输入并显示数组内容。修改后,array.c 如下所示。
Jerry had committed the first version of the code. But he thinks that he should write two functions to accept input and to display array contents. After modification, array.c looks as follows.
#include <stdio.h>
#define MAX 16
void accept_input(int *arr, int n) {
int i;
for (i = 0; i < n; ++i)
scanf("%d", &arr[i]);
}
void display(int *arr, int n) {
int i;
for (i = 0; i < n; ++i)
printf("|%d| ", arr[i]);
printf("\n");
}
int main(void) {
int i, n, arr[MAX];
printf("Enter the total number of elements: ");
scanf("%d", &n);
printf("Enter the elements\n");
accept_input(arr, n);
printf("Array has following elements\n");
display(arr, n);
return 0;
}
Jerry 编译并测试了他的代码,并准备提交更改。在此之前,他希望使用以下命令查看更改。
Jerry compiles and tests his code and is ready to commit changes. Before that, he wants to review the changes using the following command.
[jerry@CentOS trunk]$ svn diff
上述命令将产生以下结果。
The above command will produce the following result.
Index: array.c
===================================================================
--- array.c (revision 2)
+++ array.c (working copy)
@@ -2,6 +2,24 @@
#define MAX 16
+void accept_input(int *arr, int n)
+{
+ int i;
+
+ for (i = 0; i & n; ++i)
+ scanf("%d", &arr[i]);
+}
+
+void display(int *arr, int n)
+{
+ int i;
+
+ for (i = 0; i < n; ++i)
+ printf("|%d| ", arr[i]);
+
+ printf("\n");
+}
+
int main(void)
{
int i, n, arr[MAX];
@@ -10,15 +28,10 @@
scanf("%d", &n);
printf("Enter the elements\n");
+ accept_input(arr, 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");
+ display(arr, n);
return 0;
}
对于新添加的行,Subversion 在行之前显示 + 符号,对于删除的行,它显示 - 符号。现在,Jerry 尝试使用以下命令提交更改:
For the new added lines, Subversion shows + sign before line and for removed line it shows - sign. Now, Jerry tries to commit the changes using the following command:
[jerry@CentOS trunk]$ svn commit -m "Add function to accept input and to display array contents"
上述命令将产生以下结果。
The above command will produce the following result.
Sending trunk/array.c
svn: Commit failed (details follow):
svn: File or directory 'array.c' is out of date; try updating
svn: resource out of date; try updating
Subversion 不允许提交 Jerry 的更改,因为 Tom 已修改代码库,而 Jerry 的工作副本已过时。为避免相互覆盖更改,Subversion 会使此操作失败。Jerry 必须在提交他的更改之前更新工作副本。因此,他按照以下所示使用 update 命令。
Subversion is not allowing to commit Jerry’s changes, because Tom has already modified the repository and Jerry’s working copy is out of date. To avoid overwriting each other’s changes, Subversion fails this operation. Jerry must update working copy before committing his changes. So he uses update command as shown below.
[jerry@CentOS trunk]$ svn update
G array.c
Updated to revision 3.
Subversion 在文件名之前显示字母 G ,表示此文件已合并。
Subversion is showing the letter G before filename, which means this file has been merged.
[jerry@CentOS trunk]$ svn diff
上述命令将产生以下结果。
The above command will produce the following result.
Index: array.c
===================================================================
--- array.c (revision 3)
+++ array.c (working copy)
@@ -2,6 +2,24 @@
#define MAX 16
+void accept_input(int *arr, int n)
+{
+ int i;
+
+ for (i = 0; i < n; ++i)
+ scanf("%d", &arr[i]);
+}
+
+void display(int *arr, int n)
+{
+ int i;
+
+ for (i = 0; i < n; ++i)
+ printf("|%d| ", arr[i]);
+
+ printf("\n");
+}
+
int main(void)
{
int i, n, arr[MAX];
@@ -15,15 +33,10 @@
}
printf("Enter the elements\n");
+ accept_input(arr, 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");
+ display(arr, n);
return 0;
}
Subversion 只显示 Jerry 的更改,但 array.c 文件已合并。如果您仔细观察,Subversion 现在显示版本号 3。在之前的输出中,显示的是版本号 2。只需查看是谁对该文件进行了更改以及出于什么目的。
Subversion is showing only Jerry’s changes, but array.c file is merged. If you observe carefully, Subversion is now showing revision number 3. In the previous output, it was showing revision number 2. Just review who made changes in the file and for what purpose.
jerry@CentOS trunk]$ svn log
------------------------------------------------------------------------
r3 | tom | 2013-08-18 20:21:50 +0530 (Sun, 18 Aug 2013) | 1 line
Fix array overflow problem
------------------------------------------------------------------------
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
------------------------------------------------------------------------
现在,Jerry 的工作副本已与存储库同步,他可以安全地提交更改。
Now Jerry’s working copy is synchronized with the repository and he can safely commit his changes.
[jerry@CentOS trunk]$ svn commit -m "Add function to accept input and to display array contents"
Sending trunk/array.c
Transmitting file data .
Committed revision 4.