Svn 简明教程
SVN - Resolve Conflicts
Tom 决定为他们的项目添加一个 README 文件。于是,他创建了 README 文件并在其中添加了待办事项列表。添加此内容后,文件存储库位于修订版本 6。
Tom decides to add a README file for their project. So he creates the README file and adds TODO list into that. After adding this, the file repository is at revision 6.
[tom@CentOS trunk]$ cat README
/* TODO: Add contents in README file */
[tom@CentOS trunk]$ svn status
? README
[tom@CentOS trunk]$ svn add README
A README
[tom@CentOS trunk]$ svn commit -m "Added README file. Will update it's content in future."
Adding trunk/README
Transmitting file data .
Committed revision 6.
Jerry 签出了位于修订版本 6 的最新代码。他立即开始工作。几个小时后,Tom 更新了 README 文件并提交了他的更改。修改后的 README 将如下所示。
Jerry checks out the latest code which is at revision 6. And immediately he starts working. After a few hours, Tom updates README file and commits his changes. The modified README will look like this.
[tom@CentOS trunk]$ cat README
* Supported operations:
1) Accept input
2) Display array elements
[tom@CentOS trunk]$ svn status
M README
[tom@CentOS trunk]$ svn commit -m "Added supported operation in README"
Sending trunk/README
Transmitting file data .
Committed revision 7.
现在,存储库位于修订版本 7,而 Jerry 的工作副本已过期。Jerry 还更新了 README 文件并尝试提交他的更改。
Now, the repository is at revision 7 and Jerry’s working copy is out of date. Jerry also updates the README file and tries to commit his changes.
Jerry 的 README 文件如下所示。
Jerry’s README file looks like this.
[jerry@CentOS trunk]$ cat README
* File list
1) array.c Implementation of array operation.
2) README Instructions for user.
[jerry@CentOS trunk]$ svn status
M README
[jerry@CentOS trunk]$ svn commit -m "Updated README"
Sending trunk/README
svn: Commit failed (details follow):
svn: File or directory 'README' is out of date; try updating
svn: resource out of date; try updating
Step 1: View Conflicts
Subversion 检测到自上次更新以来 README 文件已更改。因此,Jerry 必须更新他的工作副本。
Subversion has detected that the README file has changed since last updated. So, Jerry has to update his working copy.
[jerry@CentOS trunk]$ svn up
Conflict discovered in 'README'.
Select: (p) postpone, (df) diff-full, (e) edit,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options:
Subversion 抱怨与 README 文件有冲突,并且 Subversion 不知道如何解决此问题。于是 Jerry 选择了 df 选项来查看冲突。
Subversion is complaining that there is a conflict with the README file, and Subversion does not know how to solve this. So Jerry chooses the df option to review the conflict.
[jerry@CentOS trunk]$ svn up
Conflict discovered in 'README'.
Select: (p) postpone, (df) diff-full, (e) edit,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: df
--- .svn/text-base/README.svn-base Sat Aug 24 18:07:13 2013
+++ .svn/tmp/README.tmp Sat Aug 24 18:13:03 2013
@@ -1 +1,11 @@
-/* TODO: Add contents in README file */
+<<<<<<< .mine
+* File list
+
+1) array.c Implementation of array operation.
+2) README Instructions for user.
+=======
+* Supported operations:
+
+1) Accept input
+2) Display array elements
+>>>>>>> .r7
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options:
Step 2: Postpone Conflicts
接下来,Jerry 选择了延期 (p) 选项,以便他可以解决冲突。
Next Jerry chooses the postpone(p) options, so that he can resolve the conflict.
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: p
C README
Updated to revision 7.
Summary of conflicts:
Text conflicts: 1
在文本编辑器中打开 README 后,他意识到 Subversion 已包含 Tom 的代码和他的代码以及冲突标记。
After opening the README in text editor he realizes that Subversion has included both Tom’s code and his code with conflict markers.
[jerry@CentOS trunk]$ cat README
<<<<<<< .min
* File list
1) array.c Implementation of array operation.
2) README Instructions for user.
=======
* Supported operations:
1) Accept input
2) Display array elements
>>>>>>> .r7
Jerry 想要 Tom 的更改以及他的更改,于是他只删除了包含冲突标记的行。
Jerry wants Tom’s changes as well as his, so he just removes the lines containing the conflict markers.
因此,修改后的 README 看起来像这样。
So, the modified README will look like this.
[jerry@CentOS trunk]$ cat README
* File list
1) array.c Implementation of array operation.
2) README Instructions for user.
* Supported operations:
1) Accept input
2) Display array elements
Jerry 解决冲突并重新提交。
Jerry resolved the conflict and he retries commit.
[jerry@CentOS trunk]$ svn commit -m "Updated README"
svn: Commit failed (details follow):
svn: Aborting commit: '/home/jerry/project_repo/trunk/README' remains in conflict
[jerry@CentOS trunk]$ svn status
? README.r6
? README.r7
? README.mine
C README
Step 3: Resolve Conflicts
在上述提交中,字母 C 指示 README 文件中存在冲突。Jerry 解决了冲突,但没有告诉 Subversion 他已解决冲突。他使用 resolve 命令通知 Subversion 关于冲突解决。
In the above commit, the letter C indicates that there is a conflict in the README file. Jerry resolved the conflict but didn’t tell Subversion that he had resolved the conflict. He uses the resolve command to inform Subversion about the conflict resolution.
[jerry@CentOS trunk]$ svn resolve --accept=working README
Resolved conflicted state of 'README'
[jerry@CentOS trunk]$ svn status
M README
[jerry@CentOS trunk]$ svn commit -m "Updated README"
Sending trunk/README
Transmitting file data .
Committed revision 8.