iOS使用Xcode9自带Git进行本地版本控制的记录
1.创建项目时,添加Git管理:创建项目时选中Create Git reposity on my mac

2.已存在项目,添加Git管理:选中Source Control菜单,点击Create Git Repositories

3.使用Git命令给已存在的项目添加Git管理
$ cd 项目路径(直接将创建后的项目文件夹拖到此处)
$ git init
创建成功会显示:命令行提示这是一个空的仓库
Initialized empty Git repository in /Users/XXX/Desktop/CFLogDemo/.git/
已经存在Git会显示:
Reinitialized existing Git repository in /Users/XXX/Desktop/CFLogDemo/.git/

4.点击左侧第二个按钮,看到Branches、Tags、Remotes三个文件,展开Branches,会看到一个分支master,点击master,会看到一个系统初始化时自动提交的版本(注释为 Initial Commit)

5.修改代码后,选择Source control 菜单,点击commit提交Git
修改文件,显示M;新增文件,显示A


直接点击Commit 5 Files提交按钮,会弹出下面的提示:需要填写更改备注


6.提交成功后,会新增一行Git版本信息

7.新建分支:选中master分支,右键,点击 branch from “master”



以后再提交新的版本,版本修改信息都显示在developer分支下,master下更新内容不变

8.版本回退,双击更新信息,可以显示修改的文件,点击文件,出现前后两个版本对比框

版本回退命令:
// 回到当前版本,放弃所有没有提交的修改
$ git reset --hard HEAD
// 回到上一个版本
$ git reset --hard HEAD^
// 回到之前第3个修订版本
$ git reset --hard HEAD~3
// 回到指定版本号的版本
$ git reset --hard [版本号前7位]
// 查看文件的修改日志
$ git log

// 查看指令使用记录(能显示所有的版本号)
$ git reflog

回退到上一版本:$ git reset --hard HEAD^

修改当前分支:$ git checkout master


9.合并分支,将developer上更新的版本合并到master:右击developer,选中merge “developer” into “master”




9.删除分支:选中要删除的分支developer,右击,delete
