集中式版本控制工具
1.版本库放在中央服务器,团队里面的每个人工作的时候都要从中央服务器下载代码
2.必须联网才能进行工作
3.个人修改后,提交到中央版本库
举例:SVN和CVS
分布式版本控制工具
1.分布式版本控制系统没有中央服务器,每个人的电脑上都是一个完整的版本库。
2.工作的时候,不需要联网。因为版本库就在你自己的电脑上。
3.多人协作只需要把各自的修改推送给对方,就能互相看到对方的修改了
举例:Git
Git工作流程图

Git配置
1.Git GUI:Git提供的图形界面工具
2.Git Bash:Git提供的命令行工具
基本配置
1.打开Git Bash
2.设置用户信息

3.查看配置信息

4.为常用指令配置别名
有些常用的指令参数非常多,每次都要输入好多参数,我们可以使用别名 4.1.打开用户目录,创建.bashrc文件  4.2.在.bashrc文件下输入如下内容
#用于输出git提交日志
alias git-log='git log --pretty=oneline --all --graph --abbrev-commit'
#用于输出当前目录所有文件及基本信息
alias ll='ls -al'
4.3.解决中文乱码问题
4.3.1 打开GitBash执行下面命令
git config --global core.quoteepath false
4.3.2 在Git安装目录下 /etc/bash.bashrc文件最后加入下面两行(我的Git安装在D盘)
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
获取本地仓库
要使用Git对代码进行版本控制,首先要获得本地仓库
1.新建一个空目录作为本地git仓库
2.进入目录点击Git Bash
3.执行git init
4.创建成功后可以看到隐藏的.git目录

git常用指令

1.查看修改的状态(工作区、暂存区)
git status
2.添加工作区到暂存区
git add 单个文件名|通配符(.)
git add .
3.提交暂存区到本地仓库
git commit -m "注释内容"
4.查看提交日志

5.版本回退(撤销)

查看日志 git log
以精简的方式显示提交记录(已经配好别名的情况下) git-log
添加文件名至忽略列表

touch .gitignore
分支
几乎所有的版本控制系统都以某种形式支持分支。使用分支意味着你可以把你的工作从开发主线上分离开来进行重大的BUG修改。开发新的功能,以免影响开发主线   查看分支,使用git-log较为方便    不是同一文件同一行的,git会自动合并分支 
Git远程仓库
1.常用的(代码托管服务)远程仓库

2.在码云上搭建私服
2.1创建仓库

2.2 配置SSH公钥
1.生成SSH公钥
ssh-keygen -t -rsa
之后不断回车,如果公钥已经存在,则自动覆盖
2.Gitee设置账号共公钥
获取公钥
cat ~/.ssh/id_rsa.pub
 将公钥粘贴在gitee上边  3.验证是否配置成功
ssh -t git@gitee.com
4.操作远程仓库
1.连接远程仓库 git remote add origin 远程仓库ssh地址 //origin为远程仓库别名   2.将本地代码同步到远程仓库
git push [-f] [--set-upstream] [远端名称[本地分支名][:远端分支名]]
git push origin master:master
//-f为强制覆盖
//--set-upstream 推送到远端的同时建立起和远端的关联关系
git push origin --set-upstream 0master:master
 5.从远程仓库克隆
如果有一个远端仓库,可以直接克隆到本地
git clone <仓库路径> [本地目录]
//本地目录可以省略,会自动生成一个目录
6.从远程仓库抓取和拉取
抓取:就是将仓库里面的更新都抓取到本地,不会进行合并 拉取:将远程仓库里面的修改拉到本地并自动进行合并,等同于fetch+merge
//抓取
git fetch [remote name] [branch name]
//拉取
git pull [remote name] [branch name]
7.解决冲突 A先将文件push到远程仓库,为了避免冲突 B要先在本地git pull,修改冲突的地方之后提交到本地仓库再push到远程仓库
|