Loading... <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">在Windows环境中,我们一般使用TortoiseSVN来搭建svn环境。在Mac环境下,由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装任何第三方软件的前提下使用svn功能,不过还需做一下简单的配置。</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">我们首先来看下,如何在Mac环境下搭建svn服务器端环境。</span> </p> <h2 style="margin:0px;padding:0px;font-family:Arial;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">创建代码仓库,用来存储客户端所上传的代码</span> </h2> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">我先在/User/apple目录下新建一个svn目录,以后可以在svn目录下创建多个仓库目录<br /> </span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">打开终端,创建一个mycode仓库,输入指令:<strong>svnadmin create /Users/apple/svn/mycode</strong></span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">指令执行成功后,会发现硬盘上多了个/Users/apple/svn/mycode目录,目录结构如下:</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;"><img src="https://blog.litchi.ren//content/uploadfile/201705/4f6f2b484e26814a18d9a58892f8893c20170501114830.png" alt="" style=""><br /> </span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;"> <h2 style="margin:0px;padding:0px;font-family:Arial;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">配置svn的用户权限</span> </h2> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">主要是修改/svn/mycode/conf目录下的三个文件</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">1.打开svnserve.conf,将下列配置项前面的<span style="color:#FF0000;">#</span>和<span style="color:#FF0000;">空格</span>都去掉</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;"> <pre class="prettyprint lang-bsh linenums"># anon-access = read # auth-access = write # password-db = passwd # authz-db = authz </pre> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">anon-access = read代表匿名访问的时候是只读的,若改为anon-access = none代表禁止匿名访问,需要帐号</span>密码才能访问 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">2.打开passwd,在[users]下面添加帐号和密码,比如:</span> </p> <pre class="prettyprint lang-bsh linenums">[users] mj = 123 jj = 456 </pre> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">帐号是mj,密码是123</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">3.打开authz,配置用户组和权限</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">我们可以将在passwd里添加的用户分配到不同的用户组里,以后的话,就可以对不同用户组设置不同的权限,没有必要对每个用户进行单独设置权限。</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">在[groups]下面添加组名和用户名,多个用户之间用逗号(,)隔开</span> </p> <pre class="prettyprint lang-bsh linenums">[groups] topgroup=mj,jj</pre> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 说<span style="font-family:'courier new', courier;">明mj和jj都是属于topgroup这个组的,接下来再进行权限配置。</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">使用[/]代表svn服务器中的所</span>有资源库 </p> <pre class="prettyprint lang-bsh linenums">[/] @topgroup = rw </pre> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">上面的配置说明topgroup这个组中的所有用户对所有资源库都有读写(rw)权限,组名前面要用@</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">如果是用户名,不用加@,比如mj这个用户有读写权限</span> </p> <pre class="prettyprint lang-bsh linenums">[/] mj = rw</pre> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 至于其他精细的权限控制<span style="font-family:'courier new', courier;">,可以参考authz文件中的</span>其他内容 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">4.启动svn服务</span>器 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 前面配置了这么多,最关键还是看能否正常启动服务器,若启动不来,前面做再多工作也是徒劳。 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 在终端输入下列指令:<span style="font-family:'courier new', courier;"><strong>svnserve -d -r /Users/apple/svn</strong></span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 或者输入:<span style="font-family:'courier new', courier;"><strong>svnserve -d -r /Users/apple/svn</strong></span><strong><span style="font-family:'courier new', courier;">/mycode</span></strong> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 没有任何提示就说明启动成功了 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">5.关闭svn服务</span>器 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 如果你想要关<span style="font-family:'courier new', courier;">闭svn服务器</span>,最有效的办法是打开实用工具里面的“活动监视器”<img src="https://blog.litchi.ren//content/uploadfile/201705/7f8f8d7044abbcaad411c3afdfc1a01920170501114830.png" alt="" style=""> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <img src="https://blog.litchi.ren//content/uploadfile/201705/116ac5d27cd041184e936847dd1a35be20170501114831.png" alt="" style=""> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 综合上述,我们就可以轻<span style="font-family:'courier new', courier;">松搭建svn服务</span>器环境了 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <h2 style="margin:0px;padding:0px;font-family:Arial;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <a name="t2"></a><span style="font-family:'courier new', courier;">使用svn客户端功能</span> </h2> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">1.从本地导入代码到服务器(第一次初始化导入)</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">在终端中输入</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <strong><span style="font-family:'courier new', courier;">svn import /Users/apple/Documents/eclipse_workspace/weibo svn://localhost/mycode/weibo --username=mj --password=123 -m "初始化导入"</span></strong> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">我解释下指令的意思:将/Users/apple/Documents/eclipse_workspace/weibo中的所有内容,上传到服务器mycode仓库的weibo目录下,后面双引号中的"初始化导入"是注释</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">2.从服务器端下载代码到客户端本地</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">在终端中输入<strong>svn checkout svn://localhost/mycode --username=mj --password=123 /Users/apple/Documents/code</strong></span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">我解释下指令的意思:将服务器中mycode仓库的内容下载到/Users/apple/Documents/code目录中</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">3.提交更改过的代码到服务器</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">在步骤2中已经将服务器端的代码都下载到/Users/apple/Documents/code目录中,现在修改下里面的一些代码,然后提交这些修改到服务器</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">1> 打开终端,先定位到/Users/apple/Documents/code目录,输入:<strong>cd/Users/apple/Documents/code</strong></span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">2> 输入提交指令:<strong>svn commit -m "修改了main.m文件"</strong></span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">这个指令会将/Users/apple/Documents/code下的所有修改都同步到服务器端,假如这次我只修改了main.文件</span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">可以看到终端的打印信息:</span> </p> <pre class="prettyprint lang-bsh linenums">Sending weibo/weibo/main.m Transmitting file data . Committed revision 2. </pre> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">4.更新服</span>务器端的代码到客户端 </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> 这个应该是最简单的指令了,在终端中定位到客户端代码目录后,比如上面的<span style="font-family:'courier new', courier;">/Users/apple/Documents/code目录</span>,然后再输入指令:<strong><span style="font-family:'courier new', courier;">svn update</span></strong> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;">5.至于svn的其他用法,可以在终端输入:<strong>svn help</strong></span> </p> <img src="https://blog.litchi.ren//content/uploadfile/201705/cc2fd0bf6a38086c2546e27024e7eda320170501114831.png" alt="" style=""><br /> </span> </p> <p style="margin-top:0px;margin-bottom:0px;padding:0px;font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <span style="font-family:'courier new', courier;"><span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;">这里列出一大</span><span style="font-size:14px;line-height:26px;white-space:normal;font-family:'courier new', courier;background-color:#FFFFFF;">堆svn指</span><span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;">令,后面括号中的内容的一般代表着指令的简称,比如我们</span><span style="font-size:14px;line-height:26px;white-space:normal;font-family:'courier new', courier;background-color:#FFFFFF;">可以用svn ci代替svn commit,用svn co代替svn checkout</span><br /> </span> </p> </span> </p> 最后修改:2018 年 01 月 23 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏