AndroidStudio configures SVN and uses code management

Reprinted from: http://www.it165.net/pro/html/201508/51801.html

One, Android  Studio configuration SVN

Android  Studio configuration SVN is very simple, in Settings, find Version Control->Subversion; check Use command line client in General in the control panel of this page, and then browse the local SVN installation directory, select "svn.exe" is fine;
there is a Use system default Subversion configuration directory under Use command line client, this is checked by default, this is the path of svn-related configuration information, just keep the default path, but it is not found yet What needs to be modified; the above operations are as follows:

2. Associate SVN resource library with Android Studio project and add ignored files
Create a new Android project in Android Studio. After success, let's add the files to be ignored. Adding ignored files in Android Studio is different from Eclipse. On Eclipse, we can add ignore files anytime, but in Android Studio It is only effective to add ignore files before not associated with SVN (after trying many times, the ignored files are ignored successfully!). Android Studio to add ignore files is also in Ignored Files under Settings->Version Control (settings related to version control are in this directory), click the plus sign to ignore file settings, Android Studio defaults to three types of ignore The method is for developers to choose: ignore the specified file, ignore all files in the folder, and ignore files that meet the matching rules; as shown in the figure:
Click the "+" on the right to add, and "-" to delete; Android projects created by Android Studio generally need to ignore the .idea folder, .gradle folder, all build folders, all .iml files and local.properties files .
After ignoring the file, we associate the project with SVN, select VCS->Import into Version Control->Share Project (Subversion); here is one point, there are Import into Subversion and Share Project (Subversion) under Import into Version Control. One option [there is no second option in studio 1.3, only Share Project on GitHup]: The first one is to directly import the project to the SVN server, but the local project is not associated with the SVN server. After importing All the files in the project will turn red, and when submitting to the SVN server, it will be prompted that the project is not a working copy under SVN; the second is to associate the current project of Android Studio with the SVN server, but the project is not imported into SVN On the server, you need to submit the project to the SVN server again after establishing the connection. Both methods can realize the function of submitting the local code to the SVN server, but the steps are different. First, complete the association between the project in the second method and the SVN and code submission. The first method seems irregular, and I will talk about it later; The figure is the second way to associate the local project with SVN:
Then it will pop up to select the SVN address to share and other options, as shown below:
Select the second one under Define share target to create a folder for your current project under the trunk. The corresponding first option is to directly put the entire file under the trunk folder, and the third one is created under the project folder A trunk folder is created, so it is recommended to use the second method; after the selection is complete, click Share and it will pop up to let you choose the formatted version (jdk version) of the SVN working copy, as shown below:
建议选择1.8format,我之前选择了其他的试了一下,发现项目总会报出一下错误,原因暂时未发现,就先这样选择吧;点击OK等待一会就能创建本地项目同SVN服务器的关联了;成功后悔自动刷新本地的项目,待项目里的内容变成绿色的即表示已经成功了,如下图所示:
到目前为止只是将项目同SVN服务器建立了联系,并没有将代码提交到SVN服务器上去;如何提交呢,其实很简单,只需点击SVN相关操作按钮里的commit就行了(上图SVN相关操作按钮左起第二个按钮);
点击Commit后Android Studio会先对当前代码进代码分析,如果有错误或者警告会弹出如下的框,如果有错误冲突等需要解决后再提交,如果是警告可以忽略(同Eclipse相同);第一次将整个代码提交到SVN服务器时时间有可能很长,请耐心等待,之后再创建项目时就不会这么慢了。
成功后我们就完成了新建项目同SVN的关联及导入项目到SVN服务器上了。

关于第一种方式,在将本地代码导入到SVN服务器后将本地代码删除,然后从SVN服务器上将之前提交的代码更新下来,这样一来也可以同SVN建立关联正常进行开发;第一种方式和第二种方式的区别就在于:第一种是将代码先提交到SVN服务器上,然后再从SVN服务器上更新下来(本地项目同SVN服务器建立联系);第二种是先同SVN服务器监理联系,然后将代码提交到SVN服务器上去。建议使用第二种方式进行新项目的SVN关联。

 

在我的studio1.3版本里面没有share project(subvision的)只能选择直接导入项目到服务器:

加载中...

添加服务器仓库:导入项目到服务器一路next就可以啦!导入成功后本地项目就好和服务器关联起来:

稍微修改下布局看看是否关联测试下:

加载中...

加载中...

 

到Commit Changes 这里有几个选项需要了解的:

 

Auto-update after commit :自动升级后提交

keep files locked :把文件锁上,我想这应该就只能你修改其他开发人不能修改不了的功能

在你提交之前:before commit

Reformat code:重新格式化代码

Rearrange code:重新整理代码

Optimize imports:优化导入

Perform code analysis:执行代码分析[ 默认选择]

Check TODO(show all):检测需要修改的代码[显示所有默认选择]

clean up: 清除所有

Update copyright:更新版权

具体看情况选择功能点:比如不想其他人修改这些代码可以选择keep files locked

在Commit Message 添加修改信息

修改成功:

在commit 按钮下面还有一个是create patch这个选项试一下其作用:

应该明白是创建一个补丁文件主要的作用就是可以查看修改的地方:

三、Android Studio SVN代码冲突的解决
关于代码冲突解决的问题,首先要感谢一下知友ShinChven的回答建议。在使用SVN更新服务器上的代码时,有时会弹出代码冲突的对话框,问你是否进行合并,并提供了三种合并方案:accept yours(使用你的)、accept theirs(使用别人的)和merge(合并);


前两个都是进行的覆盖操作,就不多做解释了;当你选择merge合并时,会弹出代码合并对照窗口,一共有三个屏,左右两侧时你和服务器不同的代码并高亮显示不同的部分,带有箭头和叉号,通过点击箭头将两边冲突的代码添加到中间的合并区域中去,点击叉号则辨识放弃那一段代码,待所有冲突处理完成后merge就成功了。


当然在使用过程中肯定会遇到很多的问题上面的东西也是参考其他大神的,自己也添加了几点区别:到时候遇到问题再继续研究下。
继续完善:

Checkout SVN上的项目

选择subversion

 

导入项目到SVN服务器,

Import into 选择subversion

 

 

 

点击 添加服务地址例如

 

浏览SVN服务器上的项目文件夹

SVN仓库会显示文件列表

 

其他说明

 

单文件 签入当文件,右键subversion Add

文件红色:表示文件没有添加到服务器

绿色:表示没有更新新的修改到服务器

普通黑色:表示和服务器同步

文件夹颜色说明

参考 :http://blog.csdn.net/niu_hao/article/details/6774471

黄色感叹号(有冲突): --这是有冲突了,冲突就是说你对某个文件进行了修改,别人也对这个文件进行了修改,别人抢在你提交之前先提交了,这时你再提交就会被提示发生冲突,而不 允许你提交,防止你的提交覆盖了别人的修改。要解决冲突,如果你确认你的修改是无效的,则用TSVN还原你的修改就行了;如果认为你的修改是正确的,别人 的提交是无效的,那么用TSVN先标记为“解决冲突”,然后就可以提交了;如果你认为你的修改和别人的修改都有一部分是有效的,那么你就把别人的修改手动 合并到你的修改中,然后使用TSVN标注为“解决冲突”,然后就可以提交了。进入文件夹,寻找有黄色感叹号的文件,这些文件就是发生冲突的地方,根据实际 情况处理冲突 米字号(有本地修改代码): --这是说明你有未提交的本地代码。 问好(新加入的资源): --这说明该文件是项目中新增文件资源,新增资源可以是文件、图片、代码等。

红色感叹号(本地代码与库没有保持一致): --这说明本地代码跟库上没有保持一致,如果用户想修复,可以将带红色感叹号图标文件删除,直接update即可。 灰色向右箭头(本地修改过) --本地代码没有及时上库。 蓝色向左箭头(SVN上修改过) --记得更新代码后修改,提交前跟svn对比习惯。 灰色向右且中间有个加号的箭头(本地比SVN上多出的文件) --修改完记得跟svn保持一致 蓝色向左且中间有个加号的箭头(SVN上比本地多出的文件) --删除该文件后,再次更新,将svn上文件全部更新下来。 灰色向右且中间有个减号的箭头(本地删除了,而SVN上未删除的文件) --也就是说你删除确认后,一定要记得上库,跟svn保持一致 蓝色向左且中间有个减号的箭头(SVN上删除了,而本地未删除的文件) --比对svn库上代码,确定需要删除后,更新svn(删除无用代码)。 红色双向箭头(SVN上修改过,本地也修改过的文件 ) --这个表示本地和svn上都修改过,最好就是把本地修改合并到svn,修改代码前最后先更新。

 

文件状态说明:

 

单个文件签入签出操作:右键subversion

Add,添加到服务器

Commit:提交

Update:更新,获取新版本

Integrate:合并

注意:SVN和VSS不同签入前如果文件被其他人修改需要比较版本如何其他修改有效需要合并签入

整个项目更新提交:Commit ,Update

 

不知道是啥原因如果刚刚开始选择share project(subvision)的话,好像在选择commit的时候很慢,始终上传不了绿色的部分代码:

所以我直接在本地:commit到服务器里面的

Guess you like

Origin blog.csdn.net/u011326269/article/details/55192849