摘要:最佳做法是避免冲突。冲突时,不要把branch merge到trunk. 先由最新版本的trunk得到branch,然后再修改文件,直接merge过去就行。这样不会有冲突。先用svn merge --dry-run来模拟假装merge一下看是否有冲突
# svn merge --help
merge: Apply the differences between two sources to a working copy path.
usage: 1. merge sourceURL1[@N] sourceURL2[@M] [WCPATH]
2. merge sourceWCPATH1@N sourceWCPATH2@M [WCPATH]
3. merge [-c M | -r N:M] SOURCE[@REV] [WCPATH]
我们以第一个为例
merge sourceURL1[@N] sourceURL2[@M] [WCPATH]
这个help里面提示,merge需要三个参数
sourceURL1,sourceURL2的含义并不是两个分支,或者一个分支一个主干,而是同一个分支的两个状态,或者说是两个版本。对这两个版本做一个diff,然后把diff的结果,应用到最后的参数WCPATH上,WCPATH代表是一个本地已经checkout的工作区
svn merge的思想是diff and apply
比如,我开发一个项目叫做proj
目录结构是
proj/trunk
proj/branches
proj/tags
(省略了http:// 之后的,只是相对路径,但是真正使用时候不能省略)
当版本达到100的时候,我决定做一个branch进行一些其他开发
转自:http://www.blogjava.net/lingy/archive/2009/06/02/279544.html
svn resolve --accept ARG file
--accept ARG : specify automatic conflict resolution source
('base', 'working', 'mine-conflict',
'theirs-conflict', 'mine-full', 'theirs-full')
Resolve “conflicted” state on working copy files or directories. This routine does not semantically resolve conflict markers, however, it replaces PATH
with the version specified by the --accept
argument and then removes conflict-related artifact files. This allows PATH
to be committed again—that is, it tells Subversion that the conflicts have been “resolved.”. You can pass the following arguments to the --accept
command depending on your desired resolution:
Choose the file that was the BASE
revision before you updated your working copy. That is, the file that you checked out before you made your latest edits.
Assuming that you've manually handled the conflict resolution, choose the version of the file as it currently stands in your working copy.
Resolve all conflicted files with copies of the files as they stood immediately before you ran svn update.
Resolve all conflicted files with copies of the files that were fetched from the server when you ran svn update.
例子:
工程师A修改了a.txt的第一行,提交了。
工程师B也修改了a.txt的第一行,然后执行svn up,这时SVN提示了:(以下,你开始扮演工程师B的角色了)
$ svn up
在 “a.txt” 中发现冲突。
选择: (p) 推迟,(df) 显示全部差异,(e) 编辑,
(mc) 我的版本, (tc) 他人的版本,
(s) 显示全部选项:
我一般选择p(推迟),即引入冲突到本地,不过不会影响到SVN服务器端,可以放心。
OK,开始解决冲突了。
这时,会生成几个文件:
a.txt