版本控制是项目开发过程中必不可少的部分,不管是个人还是团队,灵活的使用版本控制将会使项目开发变得更加轻松。
Android Studio集成了版本控制系统,目前支持CVS、SVN、Git等主流的版本控制系统。
重点介绍目前最流行的版本控制系统Git的配置和使用。
版本控制
新建项目:GitDemo
当前项目,还未启用版本控制,启用git版本控制
菜单栏: VCS —> Enable Version Control Integration

选择git:

项目中的字体颜色从白色变成了黄色

Android Studio中的版本控制入口
有三种方式:
第一种方式:查看菜单栏上的VCS,可以看到版本控制的入口

第二种方式:右击要操作的文件或文件夹

第三种方式:底部工具栏 -> Version Control
底部工具栏会显示Version Control,如果没有显示,请点击View —> Tool Windows来显示,如图 所示

打开底部工具栏上的Version Control会打开操作面板

顶部工具栏

第一个:更新项目
第二个:提交变更
第三个:跟远程仓库中的文件进行对比
第四个:显示历史
第五个:撤消操作
Git设置
打开设置界面—>Version Control—> Git

点击Test:

配置Github账户信息
第一步:打开设置界面—>Version Control—> GitHub
第二步: 输入账户信息

第三部:测试连接是否成功

从Github克隆代码
第一步:进入克隆界面(3种方式)
第一种进入方式:
欢迎界面: Check out project from Version Control —> Github

第二种进入方式:
菜单栏: File —> New —> Project from Version Control —> Github

第三种进入方式:
菜单栏: VCS —> Checkout from Version Control —>Github

第二步:配置克隆项目地址

点击Text,检测url是否正确

最后点击Clone,打开项目即可
提交本地项目到GitHub
VCS —>Import into Version Control —> Share Project on GitHub

弹出对话框:

点击Share

点击OK即可,到github上看看是否成功

分享成功啦!
网友评论