一、Git的介绍
1.1、学习Git的原因:资源管理

1.2、SCM软件的介绍
软件配置管理(SCM)是指通过执行版本控制、变更控制的规程,以及使用合适的配置管理软件来保证所有配置项的完整性和可跟踪性。配置管理是对工作成果的一种有效保护。

二、版本控制软件
集中式版本控制;分布式版本控制;多人协作开发
2.1、版本
1、软件版本
2、文件版本
保存重要的历史记录、恢复数据
2.2、基本功能
1、保存和管理文件
2、提供客户端工具进行访问
3、提供不同版本的比对功能

2.3、集中式版本控制
中央服务器(资源库)出了故障,用户无法上传\下载资源文件

2.4、分布式版本控制
1、优点:中央服务器(资源库)出了故障,本地仓库还在(安全)
2、缺点:依赖于网络网速

三、Git和Git客户端的下载安装
3.1、Git
git下载https://git-scm.com/downloads/win
安装注意事项
1、修改安装路径
2、推荐使用notepad++
notepad++下载
https://www.notepad-plus-plus.org/downloads/
3、检验是否安装成功
3.2、Git客户端
git客服端下载https://git-scm.com/downloads/guis
注:需要翻墙,有需要的可以私信我,免费发给你

https://desktop.github.com/download/

四、Git客户端的使用
4.1、注册github/gitee用户
1、登录Github

2、确认Git账户

3、更换主题风格

4.2、Git客户端的介绍
1、主界面

2、创建一个仓库

3、打开仓库后的主界面

4、删除仓库

5、从本地导入一个仓库

4.3、原理图

4.4、版本号
版本号作用:合并时避免冲突;定位仓库中文件的位置
1、查看版本号

2、定位版本号位置
3、利用Git Bush here查看文件内容
右键-->Git Bush here

4、增加、修改、删除操作


5、忽略文件


6、加入分支后的文件信息

4.5、分支
1、创建分支、修改分支名、合并分支

2、处理冲突

3、创建标签
五、Github\Gitee的介绍和使用
5.1、Github的使用(与客户端的使用基本一致)
1、创建一个仓库


2、主界面;创建分支、标签;新增文件;删除仓库

3、从Github中克隆远程仓库到本地客户端

5.2、Github的使用(中文版的Github)
1、与Github的使用基本一致
但会比Github快,应该Github是外网,Gitee是内网

2、主界面;创建分支、标签;新增文件;删除仓库

3、从Gitee中克隆远程仓库到本地客户端

六、IDEA集成Git
6.1、检查是否需要更新

6.2、已有Github插件;下载Gitee插件

6.3、推送到远程仓库
1、Github授权IDEA登录,在Github上共享文件



2、Gitee授权IDEA登录,在Gitee上共享文件



注:也可在创建项目的同时创建Git仓库
6.4、在IDEA中操作Git基本操作

七、Git命令

7.1、仓库操作
1、创建仓库
git init

2、克隆仓库
git clone http网址
3、配置仓库
1)局部配置
git config user.name 用户名
git config user.email 邮箱

2)全局配置
git config --global user.name 用户名
git config --global user.email 邮箱

7.2、文件操作

1、查看当前状态
git status

2、增加文件到"暂存区"
git add a.txt
git add *.txt

3、移动文件到"工作区"
git rm --cached a.txt

4、提交文件到"存储区"(增删改都是提交文件-与客户端的操作相似)
git commit -m 提交信息

5、查看历史提交记录
git log --oneline

6、误删文件,回复操作
git add a.txt
git commit a.txt
....手动删除a.txt文件
git restore a.txt

git add a.txt
git commit a.txt
....手动删除a.txt文件
git add a.txt
git commit a.txt
...即最新版本库的a.txt也被删除
#不能用git restore a.txt
git log --oneline
git reset -hard a.txt的版本号
(此操作会回到a.txt提交的时候)
git revert a.txt的下一个提交的版本号
(此操作会再重新提交一次a.txt)
7.3、分支操作
1、创建分支前,master必须有文件信息,不然会报错

2、创建分支
git branch 新分支名

3、切换分支
git checkout 要切换到的分支名

4、创建并切换分支
git checkout -b 分支名

5、删除分支
git branch -b 分支名

7.4、分支和并出现冲突


1、分支的合并
git merge 分支名

2、冲突的处理

7.5、标签操作

1、显示某个文件信息
git log 版本号

2、创建标签,显示标签,利用标签显示文件
# 创建标签
git tag 标签名 文件版本号
# 显示标签
git tag
# 利用标签显示文件
git log 标签名


2、删除标签
git tag -d 标签名

3、利用标签名创建分支
git checkout -b 标签名

7.6、远程仓库操作
1、修改配置

2、需要提供安全认证

ssh-keygen -t rsa -C'SSH地址'
公钥位置(默认)



3、推送到远程仓库
git push 远程仓库名
4、拉取文件
git pull 远程仓库名
八、GitLab
搭建自己的代码托管平台(linux环境)