[svn] 解决SVN冲突攻略(手册)
评:极好
zccst翻译
Thistutorialiswalkthoughonhowtoresolveaconflictinsvn(subversion)
这个手册是解决svn冲突的攻略
FirstIwillmakeatest.txt
首先,我创建了一个名为test.txt的文件(在svn服务器端),并录入如下内容
test
NowIwillcommitthechanges
现在我们提交刚刚添加的内容
C:\workspace\test>svnci-m"makingastartingpoint"
Sending.
Sendingtest.txt
Transmittingfiledata.
Committedrevision2.
Supposewehave2users.User1andUser2.Bothofthemwillgetandupdatefromsvn
假设我们有用户1和用户2两个人通过svn客户端获取svn服务器端的文件test.txt
C:\workspace\test>svnup
Atest.txt
Atrevision2.
NowUser1willchangethefileto:
现在用户1更改文件test.txt内容为如下
User1ismakingaconflicttest
Hethencommitshischanges
然后用户1提交刚才的更改
C:\workspace\test>svnci-m"User1startingaconflict"
Sending.
Sendingtest.txt
Transmittingfiledata.
Committedrevision3.
User2nowcomesalongandchangeshislocalcopyofthefilenotknowingthatithasalreadybeenupdatedbyUser1ontheserver.
用户2也对文件test.txt做了更改,此时他并不知道用户1做了更改并已提交。
testUser2makingaconflict
Whenhetriestocommithewillgetanderrorfromsvn.
当用户2修改文件test.txt完毕后,准备提交时出错。
svn:Commitfailed(detailsfollow):
svn:Fileordirectory'test.txt'isoutofdate;tryupdating
svn:resourceoutofdate;tryupdating
SoUser2performsanupdate
根据错误提示,用户2更新了文件test.txt(此时发生了冲突)
C:\workspace\test>svnup
Conflictdiscoveredin'test.txt'.
Select:(p)postpone,(df)diff-full,(e)edit,
(mc)mine-conflict,(tc)theirs-conflict,
(s)showalloptions:
svndetectsthattheresaconflicthereandrequireyoutotakesomekindofaction.
Ifyoutype‘s’hereyouwillgetalistofthecommandsandmeaning
如果你输入s选项,则会列出所有svn解决冲突的选项,如下所示:
(e)edit-changemergedfileinaneditor#直接进入编辑
(df)diff-full-showallchangesmadetomergedfile#显示更改至目标文件的所有变化
(r)resolved-acceptmergedversionoffile
(dc)display-conflict-showallconflicts(ignoringmergedversion)#显示所有冲突
(mc)mine-conflict-acceptmyversionforallconflicts(same)#冲突以本地为准
(tc)theirs-conflict-accepttheirversionforallconflicts(same)#冲突以服务器为准
(mf)mine-full-acceptmyversionofentirefile(evennon-conflicts)#完全以本地为准
(tf)theirs-full-accepttheirversionofentirefile(same)#完全以服务器为准
(p)postpone-marktheconflicttoberesolvedlater#标记冲突,稍后解决
(l)launch-launchexternaltooltoresolveconflict
(s)showall-showthislist
【选择处理方式一:df】
Ifyoutype‘df’itwillshowyouaalltheconflictsinthefollowingformat
选择选项df,则会按如下格式显示所有冲突
Select:(p)postpone,(df)diff-full,(e)edit,
(mc)mine-conflict,(tc)theirs-conflict,
(s)showalloptions:df
---.svn/text-base/test.txt.svn-baseTueAug1010:59:382010
+++.svn/tmp/test.txt.2.tmpTueAug1011:33:242010
@@-1+1,3@@
-test
\Nonewlineatendoffile
+<<<<<<<.mine+testUser2makingconflict=======+User1ismakingaconflicttest>>>>>>>.r3
‘e’optionwillopentheconflictedfileinthetexteditorthatyouconfiguredforsvntouse.Inthiscaseitwillshow
<<<<<<<.minetestUser2makingconflict=======User1ismakingaconflicttest>>>>>>>.r3
Youcanresolvetheconflictherebychangingthetexttowhatyoudesire.
Forexample:
你可以解决冲突通过改变文件内容,例如vimtest.txt
User1ismakingaconflicttestUser2makingconflict
saveyourchangesandexityourtexteditoranditwillgiveyoutheconflictoptionsagain.Nowifyouusethe‘r’itwillmarkthefileismergedwitha‘G’.Astatusof‘G’meanstherewasaconflictandithasbeenresolved.
保存更改,又出现刚才的选项。此时你使用r选项,则会合并文件。如下所示:
Select:(p)postpone,(df)diff-full,(e)edit,(r)resolved,
(mc)mine-conflict,(tc)theirs-conflict,
(s)showalloptions:e
Select:(p)postpone,(df)diff-full,(e)edit,(r)resolved,
(mc)mine-conflict,(tc)theirs-conflict,
(s)showalloptions:r
Gtest.txt
Updatedtorevision3.
youcannowcheckthestatuswithsvnstatus.Youseethattest.txtismarkedas‘M’allthatslefttodoiscommit.
检查svn状态,你会发现文件test.txt前面已变成M
C:\workspace\test2>svnst
Mtest.txt
C:\workspace\test2>svnci-m"conflictresolved"
Sendingtest.txt
Transmittingfiledata.
Committedrevision4.
【选择处理方式二:p】
Sometimestheconflictsareabitmoreextensiveanditrequiresmoretimeorbettertoolstoresolvetheconflictinthesecasesyoucanchose‘p’topostponetheresolution.
有时,冲突会复杂一些,可能需要借助其他工具才能解决,这时你可以使用选项p
Select:(p)postpone,(df)diff-full,(e)edit,(r)resolved,
(mc)mine-conflict,(tc)theirs-conflict,
(s)showalloptions:p
Ctest.txt
Updatedtorevision3.
Summaryofconflicts:
Textconflicts:1
Nowifyoulookinyourdirectoryyouwillseethatsvnhascreatedafewextrafilesforyou.
此时,查看当前文件夹下,出现了如下几个文件
08/10/201011:44AM94test.txt
08/10/201011:44AM26test.txt.mine
08/10/201011:44AM27test.txt.r2
08/10/201011:44AM31test.txt.r3
Thetest.txtfileisnowafilewithbothUser2andUser1′schangesbutmarked.
文件test.txt包含了用户1和用户2的更改。
<<<<<<<.minetestUser2makingconflict=======User1ammakingaconflicttest>>>>>>>.r3
test.txt.mineisUser2′scopy.
文件.txt.mine保存了用户2的内容
testUser2makingconflict
test.txt.r2istheoriginalbasecopy
文件.txt.r2是未冲突前的内容
test
test.txt.r3isthecopyUser1commited
文件.txt.r3保存了用户1的内容
User1ismakingaconflicttest
Atthispointyoucanchooseyourfavoritemergetoolstomergethedifferencesinafile.
这种情况下,你可以选择自己喜欢的对比工具,查看差别。
Isuggestmergingthedifferencesintotest.txtandthedoa
我建议和并不同至文件test.txt中,如果如下命令:
C:\workspace\test>svnresolve--acceptworkingtest.txt
Resolvedconflictedstateof'test.txt'
Youcanalsouseanyoftheotherfilesifyouwantedtoandjustpassresolve–acceptadifferentargument.Herearethevalidarguments
当然,你也可以使用其他文件,使用resolve-accept加其他参数,共6个
实例:
svnresolvemail.sh--accept'mine-conflict'#解决冲突。
svnresolvedmail.sh#告知svn。4个文件中的其他3个消失
(1)#svnresolve–acceptbase
ChoosethefilethatwastheBASErevisionbeforeyouupdatedyourworkingcopy.Thatis,thefilethatyoucheckedoutbeforeyoumadeyourlatestedits.
使用1.txt.r2作为最后提交的版本
(2)#svnresolve–acceptworking
Assumingthatyou'vemanuallyhandledtheconflictresolution,choosetheversionofthefileasitcurrentlystandsinyourworkingcopy.
使用当前拷贝即test.txt作为最后提交的版本
(3)#svnresolve–acceptmine-full
Resolveallconflictedfileswithcopiesofthefilesastheystoodimmediatelybeforeyouransvnupdate.
使用test.txt.mine作为最后提交的版本
(4)#svnresolve–accepttheirs-full
Resolveallconflictedfileswithcopiesofthefilesthatwerefetchedfromtheserverwhenyouransvnupdate.
使用test.txt.r3作为最后提交的版本
(5)#svnresolve–acceptmine-conflict
冲突的部分以本地修改为准
(6)#svnresolve–accepttheirs-conflict
冲突的部分以服务器端修改为准
执行一下:svnresolvedtest.txt。
Nowyouarereadytocommit.
然后提交
C:\workspace\test>svnci-m"conflictresolved"
Sendingtest.txt
Transmittingfiledata.
Committedrevision4.