Subversion版本控制 — 冲突处理(二)

引言

对于一个文件,两个用户分别做了修改,如果他们的修改集changeset是有重叠的且不相同,
那么就会产生冲突。假设有一文件:
A
B
两个用户分别修改:
C                 A
A        和      B
B                  D
他们不会产生冲突,因为他们的修改没有交集。如果做如下修改:
A                  A
C       和       D
B                  B
他们的修改就有冲突了,这时就需要他们协商解决了。

概述

什么时候会发生冲突呢?
当文件的状态为:Locally changed, and out-of-date。
The file has been changed both in the working directory, and in the repository.
An svn commit of the file will fail with an out-of-date error. The file should be updated first;
an svn update command will attempt to merge the public changes with the local changes.
If subversion can't complete the merge in a plausible way automatically; it leaves it to the
user to resolve the conflict.

假设有一文件,在本地副本的修改集A不为空,在版本库的修改集B不为空。
这个时候使用svn commit,会提示错误:out-of-date,表示版本库已经发生过改变。

(1)如果A和B不重叠,则可以先使用svn update来把B合并到本地副本文件中,这个时候
A和B就共存于本地文件中。然后使用svn commit可以生成新的版本。

(2)如果A和B重叠,可能导致冲突。svn update会提示合并失败。这个时候则需要人工
进行A和B的取舍。可以选择修改集A、选择修改集B,或者融合A和B。

使用svn update时,以上两种情况的结果:

(1)G 合并成功标志。File received new changes from the repository, but your local
copy of the file had your modifications.Either the changes did not intersect, or the
changes were exactly the same as your local modifications, so Subversion has
successfully merGed the repository's changes into the file without a problem.

(2)C 冲突标志。File received Conflicting changes from the server. The changes
from the server directly overlap your own changes to the file. This overlap needs to
be resolved by a human.

检测

For every conflicted files, Subversion places up to three extra unversioned files in your
working copy.
svn update检测到冲突后,对于每个有冲突的文件,会产生三个文件。另外,原来的文件
中会多出一些冲突标志!

(1)filename.mine
This is your file as it existed in your working copy before you updated your working copy,
that is, without conflict markers. This file has your latest changes in it and nothing else.
和svn update之前的本地文件一样,含有本地修改集,即update之前的filename。

(2)filename.rOLDREV
This is the file that was the BASE revision before you updated your working copy. That is,
the file that you checkout out before you made your latest edits.
此文件是刚刚checkout时的拷贝,不含有本地修改集。

(3)filename.rNEWREV
This is the file that your Subversion client just received from the server when you updated
your working copy. This file corresponds to the HEAD revision of the repository.
版本库中的最新版本文件,含有其他人的修改集。 

检测到冲突后,SVN不允许提交冲突文件,直到以上三个文件被删除。

解决

检测到冲突后,有几种解决方法:

(1)编辑冲突文件,手动解决冲突。
Merge the conflicted text by hand, by examining and editing the conflict markers within the file.
检测到冲突后,冲突文件中会多出一些标志:
<<<<<<< .mine
本地修改集A
=======
版本库修改集B
>>>>>>>
我们只需要在以上两个区域内手动修改即可,修改后要记得删除这些冲突标志!

(2)选择filename.mine
选择此文件,表示摒弃其它人的修改,只采用我们的本地修改。即舍弃了其他人的修改集B,
采用我们的修改集A,来生成新的版本。

(3)选择filename.rOLDREV
表示既不选择本地修改集A,也不采用其他人的修改集B,最终采用的是本地checkout时的
版本。

(4)选择filename.rNEWREV
摒弃自己的修改,采用其他人的修改。摒弃自己的本地修改集A,转而采用其他人的修改集B
来生成新的版本。
等同于svn revert filename,撤销本地修改集。 

当选择好策略后,解决了冲突文件,执行svn resolved,来告知SVN冲突解决了。
之后SVN会删除这三个临时文件,并且认为文件不再处于冲突状态。
最后用svn commit来提交新版本即可。
注意:提交前要确认冲突是否真正解决,一旦三个临时文件被删除了,即使文件中仍包含
冲突标志,SVN也允许用户提交。

Author

zhangskd @ csdn

Reference

svn book

原文地址:https://www.cnblogs.com/aiwz/p/6333376.html