SVN冲突解决方法

说明

在ubuntu中,使用svn控制代码版本(其实个人喜欢GIT的,但是team使用的svn),出现冲突问题,做程序员就得上刀山下火海,不怕问题来找你,所以,本着职业的精神,好吧,解决吧。

第一次使用markdown写博客,写的时间有点久,语法不熟悉,看着语法手册一步一步创建的,大家凑合着看吧。

写在前面的话

不管是使用git还是svn,都会用到diff,查看版本之间的不同,个人不喜欢git、svn的代码比较风格,所以,配置的是BCompare4.0.7版本。在Beyond Compare官网下载LINUX版本的BCompare。

BCompare具体安装步骤

在BCompare官网下载BCompare

SVN冲突解决方法

下载的是.deb扩展的文件,双击安装即可; SVN冲突解决方法SVN冲突解决方法

安装过程中可能会要使用注册码key,一般选择试用30天,但是一般帝国大都喜欢破解版,网上有很多破解的方法,文后会附上4.0.7的破解地址;

运行,CTRL+ALT+T快捷打开命令窗口,输入bcompare回车即可运行。

SVN具体安装步骤

建议国内朋友把apt资源镜像库修改为国内的镜像:

修改方法:

Bash
~$ sudo vim /etc/apt/sources.list

在vim编辑器中使用全局替换,将系统的镜像地址替换为上述所说的国内镜像,一般选择阿里云的,vim替换命令: :%s/mirrors.ubuntu.com/mirrors.aliyun.com/g

参数说明:s是替换,g是全局

%s相当于1,$s,即从头到尾替换

/a/b/中参数为替换参数,意思是把a替换为b 

SVN冲突解决方法

vim中输入命令:wq回车退出vim编辑器

Bash
~$ sudo apt-get upgrade # 更新apt库
~$ sudo apt-get update
~$ sudo apt-get install svn # 安装svn

SVN安装结束!!!

SVN配置BCompare

这里使用了csdn上zzqhost的文章《用beyondcompare来diff SVN中的代码》。

  • 新建一个mydiff.sh文件,在目录~/.subversions/下,新建脚本文件 mydiff.sh, 内容如下: bash ~$ sudo vim mydiff.sh

  • 打开编辑器,写入下面的shell代码,并给其添加可执行权限:

vim
#!/bin/sh
# Configure your favorite diff program here.

DIFF="/usr/bin/bcompare"
# DIFF="/usr/bin/meld"
# DIFF="/usr/bin/kompare"
# DIFF=env LANG=zh_CN.UTF-8 WINEPREFIX="/home/borqs/.wine" wine "C:\\Program Files\\Beyond Compare 2\\BC2.exe"
# Subversion provides the paths we need as the sixth and seventh 
# parameters.

LEFT=${6}
RIGHT=${7}

# Call the diff command (change the following line to make sense for
# your merge program).

$DIFF $LEFT $RIGHT 

# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.

return 0
  • 修改config文件.

修改目录~/.subversions/下的文件config, 加入如下一行:

diff-cmd = /home/zzq/.subversion/mydiff.sh

现在说说如何解决冲突问题

当使用svn up更新代码的时候,出现了冲突(具体显示什么信息已忘记)。如果忘记有哪些冲突,请使用命令svn resolve查看:

Bash
joyven@joyven-ThinkPad-E450:/var/www/weimob/2.0/trunk$ svn resolve

SVN冲突解决方法

由图可知,在文件“app/modules/merchant/views/replys/subscribereply.php”中发现冲突。

选择: (p) 推迟, (df) 显示差异, (e) 编辑文件, (m) 合并, (mc) 我这边的冲突, (tc) 他们的冲突, (s) 显示全部选项:

当我输入e进行编辑的时候,搜索>>>>的字符串,即可定位冲突的信息,然后看看冲突的是自己的代码还是别人的代码,通过阅读代码,保留可用的,删掉冲突的行,以及冲突标记。修改完后,根据提示信息写入修改,然后离开,退出编辑器。

接下来,又回到了选择的那一块了,输入:df,回车看看什么情况:

vim
— app/modules/merchant/views/replys/subscribereply.php.r27619 - 别人的 

+++ app/modules/merchant/views/replys/subscribereply.php - 已合并 

@@ -725,7 +725,7 @@ 

</div> 

<div class="form-actions"> 

<!-- <input type="hidden" name="reply_id" id="reply_id" value="140841">--> 

- <input type="hidden" name="news_reply_type" id="news_reply_type" value="<?php echo empty($newsmaterial['news_reply_type']) ? '' : $newsmaterial['news_reply_type'];?>"> 

+ <input type="hidden" name="news_reply_type" id="news_reply_type" value="<?php if(isset($newsmaterial['news_reply_type'])){echo $newsmaterial['news_reply_type'];}?>"> <input type="hidden" name="news_reply_type" >id="news_reply_type" value="<?php echo empty($newsmaterial['news_reply_type']) ? '' : $newsmaterial['news_reply_type'];?>">



<button type="submit" class="btn btn-primary" id ="bsubmit">保存</button> 

<!-- <button type="button" class="btn" onclick="window.location='/insidepage/reply/by-repaly.html'"> 切换到图文模式 </button>--> 

选择: (p) 推迟, (df) 显示差异, (e) 编辑文件, (m) 合并, (r) mark resolved, 

(mc) 我这边的冲突, (tc) 他们的冲突, (s) 显示全部选项:

这时候,代码已经合并成功了,如果不相信,请继续输入df或者m看看,由于前面输入过df,现在输入m尝试一下吧:

vim
正在合并“app/modules/merchant/views/replys/subscribereply.php”。 

Conflicting section found during merge: 

(1) 他们的版本 (728) |(2) 你的版本 (728) 

————————————–+————————————– 

<input| <input 

————————————–+————————————– 

Select: (1) use their version, (2) use your version, 

(12) their version first, then yours, 

(21) your version first, then theirs, 

(e1) edit their version and use the result, 

(e2) edit your version and use the result, 

(eb) edit both versions and use the result, 

(p) postpone this conflicting section leaving conflict markers, 

(a) abort file merge and return to main menu: *1* 

“app/modules/merchant/views/replys/subscribereply.php”的合并完成。 

选择: (p) 推迟, (df) 显示差异, (e) 编辑文件, (m) 合并, (r) mark resolved, 

(mc) 我这边的冲突, (tc) 他们的冲突, (s) 显示全部选项: *r* 

“app/modules/merchant/views/replys/subscribereply.php”的冲突状态已解决

输入m看到的信息如上(除了最后一行),然后我们输入1,告诉svn使用他们的版本,然后svn告诉我们合并完成。最后输入r,显示冲突已解决。当我们回到命令窗口,输入svn resolove的时候,发现什么都没有输出,这说明冲突确实解决了,并且告诉了svn。

附加信息

上一篇:Curl POST to HTTPS url gives SSLRead() error:curl: (56) SSLRead() return error -9806


下一篇:ubuntu禁用笔记本触摸板