[TOC]
GIt使用教程
GIT基本使用代码
GIT介绍
git clone
- 效果:从git服务器下载文件,通过链接下载
- 从仓库里面获取文件
- 使用教程
git config
- 效果:配置开发者用户名和邮箱
- 每次代码提交的时候都会生成一条提交记录,其中会包含当前配置的用户名和邮箱
- 使用教程
git branch
- 效果:创建、重命名、查看、删除项目分支,通过
Git
做项目开发时,一般都是在开发分支中进行,开发完成后合并分支到主干。 - 使用教程
- 创建一个名为
daily/0.0.0
的日常开发分支,分支名只要不包括特殊字符即可。
- 如果觉得之前的分支名不合适,可以为新建的分支重命名,重命名分支名为
daily/0.0.1
- 通过不带参数的branch命令可以查看当前项目分支列表
- 如果分支已经完成使命则可以通过
-d
参数将分支删除,这里为了继续下一步操作,暂不执行删除操作
git checkout
- 切换分支,可以理解为切换文件夹
- 使用教程
- 切换到
daily/0.0.1
分支,后续的操作将在这个分支上进行
git status
- 查看文件变动状态
- 使用教程
- git status
git add
- 添加文件变动到暂存区
- 使用教程
- 通过指定文件名
README.md
可以将该文件添加到暂存区,如果想添加所有文件可用git add .
命令,这时候可通过git status
看到文件当前状态Changes to be committed:
(文件已提交到暂存区)
git commit
- 提交文件变动到版本库
- 使用方法
- 通过
-m
参数可直接在命令行里输入提交描述文本
git push
- 将本地的代码改动推送到服务器
- 使用教程
origin
指代的是当前的git服务器地址,这行命令的意思是把daily/0.0.1
分支推送到服务器
- 成功执行的反馈信息
git pull
- 将服务器上的最新代码拉取到本地
- 使用教程
git log
- 查看版本提交记录
- 使用教程
git tag
- 为项目标记里程碑
- 使用教程
- 当我们完成某个功能需求准备发布上线时,应该将此次完整的项目代码做个标记,并将这个标记好的版本发布到线上,这里我们以
publish/0.0.1
为标记名并发布,当看到命令行返回如下内容则表示发布成功了
git merge
- 合并分支
- 使用教程
- 当我们需要将本地分支合并