在Mac环境下,由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装任何第三方软件的前提下使用svn功能,不过还需做一下简单的配置。
我们首先来看下,如何在Mac环境下搭建svn服务器端环境。
创建代码仓库,用来存储客户端所上传的代码
我先在/User/apple目录下新建一个svn目录,以后可以在svn目录下创建多个仓库目录
打开终端,创建一个mycode仓库,输入指令:svnadmin create /Users/apple/svn/mycode
指令执行成功后,会发现硬盘上多了个/Users/apple/svn/mycode目录,目录结构如下:
配置svn的用户权限
主要是修改/svn/mycode/conf目录下的三个文件
1.打开svnserve.conf,将下列配置项前面的#和空格都去掉
anon-access = read代表匿名访问的时候是只读的,若改为anon-access = none代表禁止匿名访问,需要帐号密码才能访问
2.打开passwd,在[users]下面添加帐号和密码,比如:
- [users]
- mj = 123
- jj = 456
帐号是mj,密码是123
3.打开authz,配置用户组和权限
我们可以将在passwd里添加的用户分配到不同的用户组里,以后的话,就可以对不同用户组设置不同的权限,没有必要对每个用户进行单独设置权限。
在[groups]下面添加组名和用户名,多个用户之间用逗号(,)隔开
- [groups]
- topgroup=mj,jj
说明mj和jj都是属于topgroup这个组的,接下来再进行权限配置。
使用[/]代表svn服务器中的所有资源库
- [/]
- @topgroup = rw
上面的配置说明topgroup这个组中的所有用户对所有资源库都有读写(rw)权限,组名前面要用@
如果是用户名,不用加@,比如mj这个用户有读写权限
- [/]
- mj = rw
至于其他精细的权限控制,可以参考authz文件中的其他内容
4.启动svn服务器
前面配置了这么多,最关键还是看能否正常启动服务器,若启动不来,前面做再多工作也是徒劳。
在终端输入下列指令:svnserve -d -r /Users/apple/svn
或者输入:svnserve -d -r /Users/apple/svn/mycode
没有任何提示就说明启动成功了
5.关闭svn服务器
如果你想要关闭svn服务器,最有效的办法是打开实用工具里面的“活动监视器”
综合上述,我们就可以轻松搭建svn服务器环境了
使用svn客户端功能
1.从本地导入代码到服务器(第一次初始化导入)
在终端中输入
svn import /Users/apple/Documents/eclipse_workspace/weibo svn://localhost/mycode/weibo(如果是在同一台电脑上搭建的svn服务器,那么就是前面的地址,如果是其他svn服务器,写对应的svn地址,如:用https://192.168.2.78/svn/zhkt替换前面地址) --username=mj --password=123 -m "初始化导入"
我解释下指令的意思:将/Users/apple/Documents/eclipse_workspace/weibo中的所有内容,上传到服务器mycode仓库的weibo目录下,后面双引号中的"初始化导入"是注释
2.从服务器端下载代码到客户端本地
在终端中输入svn checkout svn://localhost/mycode(如果是在同一台电脑上搭建的svn服务器,那么就是前面的地址,如果是其他svn服务器,写对应的svn地址,如:用https://192.168.2.78/svn/zhkt替换前面地址) --username=mj --password=123 /Users/apple/Documents/code
我解释下指令的意思:将服务器中mycode仓库的内容下载到/Users/apple/Documents/code目录中
3.提交更改过的代码到服务器
在步骤2中已经将服务器端的代码都下载到/Users/apple/Documents/code目录中,现在修改下里面的一些代码,然后提交这些修改到服务器
1> 打开终端,先定位到/Users/apple/Documents/code目录,输入:cd/Users/apple/Documents/code
2> 输入提交指令:svn commit -m "修改了main.m文件"
这个指令会将/Users/apple/Documents/code下的所有修改都同步到服务器端,假如这次我只修改了main.文件
可以看到终端的打印信息:
- Sending weibo/weibo/main.m
- Transmitting file data .
- Committed revision 2.
4.更新服务器端的代码到客户端
这个应该是最简单的指令了,在终端中定位到客户端代码目录后,比如上面的/Users/apple/Documents/code目录,然后再输入指令:svn update
5.至于svn的其他用法,可以在终端输入:svn help
这里列出一大堆svn指令,后面括号中的内容的一般代表着指令的简称,比如我们可以用svn ci代替svn commit,用svn co代替svn checkout
推荐链接:https://www.cnblogs.com/liwanggui/archive/2016/06/28/5624147.html
冲突解决:::::::::::::::::::::
If you type ‘s’ here you will get a list of the commands and meaning
如果你输入s选项,则会列出所有svn解决冲突的选项,如下所示:(e) edit - change merged file in an editor #直接进入编辑
(df) diff-full - show all changes made to merged file #显示更改至目标文件的所有变化
(r) resolved - accept merged version of file
(dc) display-conflict - show all conflicts (ignoring merged version) #显示所有冲突
(mc) mine-conflict - accept my version for all conflicts (same) #冲突以本地为准
(tc) theirs-conflict - accept their version for all conflicts (same) #冲突以服务器为准
(mf) mine-full - accept my version of entire file (even non-conflicts)#完全以本地为准
(tf) theirs-full - accept their version of entire file (same) #完全以服务器为准
(p) postpone - mark the conflict to be resolved later #标记冲突,稍后解决
(l) launch - launch external tool to resolve conflict
(s) show all - show this list
【选择处理方式一:df】
If you type ‘df’ it will show you a all the conflicts in the following format
选择选项df,则会按如下格式显示所有冲突
Select: (p) postpone, (df) diff-full, (e) edit,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: df
--- .svn/text-base/test.txt.svn-base Tue Aug 10 10:59:38 2010
+++ .svn/tmp/test.txt.2.tmp Tue Aug 10 11:33:24 2010
@@ -1 +1,3 @@
-test
\ No newline at end of file
+<<<<<<< .mine +test User2 making conflict======= +User1 is making a conflict test>>>>>>> .r3
‘e’ option will open the conflicted file in the text editor that you configured for svn to use. In this case it will show
<<<<<<< .mine test User2 making conflict======= User1 is making a conflict test>>>>>>> .r3
You can resolve the conflict here by changing the text to what you desire.
For example:
你可以解决冲突通过改变文件内容,例如vim test.txt
User1 is making a conflict test User2 making conflict
save your changes and exit your text editor and it will give you the conflict options again. Now if you use the ‘r’ it will mark the file is merged with a ‘G’. A status of ‘G’ means there was a conflict and it has been resolved.
保存更改,又出现刚才的选项。此时你使用r选项,则会合并文件。如下所示:
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: e
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: r
G test.txt
Updated to revision 3.
you can now check the status with svn status. You see that test.txt is marked as ‘M’ all thats left to do is commit.
检查svn状态,你会发现文件test.txt前面已变成M
C:\workspace\test2>svn st
M test.txt
C:\workspace\test2>svn ci -m "conflict resolved"
Sending test.txt
Transmitting file data .
Committed revision 4.
【选择处理方式二:p】
Sometimes the conflicts are a bit more extensive and it requires more time or better tools to resolve the conflict in these cases you can chose ‘p’ to postpone the resolution.
有时,冲突会复杂一些,可能需要借助其他工具才能解决,这时你可以使用选项p
Select: (p) postpone, (df) diff-full, (e) edit, (r) resolved,
(mc) mine-conflict, (tc) theirs-conflict,
(s) show all options: p
C test.txt
Updated to revision 3.
Summary of conflicts:
Text conflicts: 1
Now if you look in your directory you will see that svn has created a few extra files for you.
此时,查看当前文件夹下,出现了如下几个文件
08/10/2010 11:44 AM 94 test.txt
08/10/2010 11:44 AM 26 test.txt.mine
08/10/2010 11:44 AM 27 test.txt.r2
08/10/2010 11:44 AM 31 test.txt.r3
The test.txt file is now a file with both User2 and User1′s changes but marked.
文件test.txt包含了用户1和用户2的更改。
<<<<<<< .mine test User2 making conflict======= User1 am making a conflict test>>>>>>> .r3
test.txt.mine is User2′s copy.
文件.txt.mine保存了用户2的内容
test User2 making conflict
test.txt.r2 is the original base copy
文件.txt.r2是未冲突前的内容
test
test.txt.r3 is the copy User1 commited
文件.txt.r3保存了用户1的内容
User1 is making a conflict test
At this point you can choose your favorite merge tools to merge the differences in a file.
这种情况下,你可以选择自己喜欢的对比工具,查看差别。
I suggest merging the differences into test.txt and the do a
我建议和并不同至文件test.txt中,如果如下命令:
C:\workspace\test>svn resolve --accept working test.txt
Resolved conflicted state of 'test.txt'
You can also use any of the other files if you wanted to and just pass resolve –accept a different argument. Here are the valid arguments
当然,你也可以使用其他文件,使用resolve -accept 加其他参数,共6个
实例:
svn resolve mail.sh --accept 'mine-conflict' #解决冲突。
svn resolved mail.sh #告知svn。4个文件中的其他3个消失
(1)#svn resolve –accept base
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.
使用1.txt.r2作为最后提交的版本
(2)#svn resolve –accept working
Assuming that you've manually handled the conflict resolution, choose the version of the file as it currently stands in your working copy.
使用当前拷贝即test.txt作为最后提交的版本
(3)#svn resolve –accept mine-full
Resolve all conflicted files with copies of the files as they stood immediately before you ran svn update.
使用test.txt.mine作为最后提交的版本
(4)#svn resolve –accept theirs-full
Resolve all conflicted files with copies of the files that were fetched from the server when you ran svn update.
使用test.txt.r3作为最后提交的版本
(5)#svn resolve –accept mine-conflict
冲突的部分以本地修改为准
(6)#svn resolve –accept theirs-conflict
冲突的部分以服务器端修改为准
执行一下:svn resolved test.txt。
Now you are ready to commit.
然后提交
C:\workspace\test>svn ci -m "conflict resolved"
Sending test.txt
Transmitting file data .
Committed revision 4.
git终端:git init git pull git add . git commit -m '描述' git push