http://www.runoob.com/git/git-tutorial.html
Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
Git 与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持。
版本库
下载(clone)
提交(commit)
更新(pull/fetch)
使用:
1. 安装
2. 配置
git config --global user.name "runoob"
git config --global user.email test@runoob.com
================================================
本地操作
3. 创建版本库
命令:git init
4. 将文件添加到缓存(暂存区)
命令: git add <file>
如:git add config
git add .
可以使用 git status 查看版本库状态信息
5. 提交到本地版本库
命令:git commit -m '提交消息'
可以使用 git log 查看提交日志信息
======================================================
分支
git branch ---- 查看分支
git branch <branch-name> ---- 创建新分支
git checkout <branch-name> ----- 切换分支
git checkout -b <branch-name> ------- 创建并切换到新分支中
git merge <branch-name> ----- 将指定分支内容合并到当前分支
git branch -d <branch-name> ---- 删除指定的分支
远程仓库(码云(gitee.com)/github(github.com))
1. 注册/登录
2. 生成 SSH Key
ssh-keygen -t rsa -C "youremail@example.com"
默认在系统用户目录下生成 .ssh 目录,包括 id_rsa 和 id_rsa.pub 两个文件,后缀为 .pub 的为公钥文件,另外一个是私钥文件
3. 将公钥文件内容复制到码云账户中配置SSH KEY
输入 ssh -T git@gitee.com 来验证是否能够认证成功
4. 新建远程空白仓库
5. 将本地已有仓库上传到远程仓库
git remote add origin git@gitee.com:mobiletrain/h51806.git
-- 添加本地仓库与远程仓库的联系
git push -u origin master
-- 将本地仓库内容推送到远程仓库
-- -u 是指明以后 git push 时都是默认提交到远程仓库 origin 中
git使用流程:
0. 配置SSH KEY
1. 本地没有源代码,则克隆(下载)源代码:
git clone 远程仓库的URL
本地有源代码,则更新源代码:
git pull
2. 在工作空间中实现编码
3. 在完成一个功能并通过调试后,提交本地版本库
git add .
git commit -m "xxxxx"
4. 将本地版本仓库内容推送到远程仓库中
git push
git更新仓库地址
1.修改远程仓库地址
git remote set-url origin URL:更换远程仓库地址,URL为新地址
PS:此方法修改切换仓库后不用关联分支,直接可以pull和push
2.先删除远程仓库,然后在添加
git remote rm origin:删除现有远程仓库
git remote add origin url:添加新远程仓库
PS:此方法需要重新关联分支:git branch --set-upstream-to=origin/远程分支 本地分支
3.查看远程仓库的地址
git remote -v