一、git的定义与配置
世界上最先进的分布式版本管理系统没有之一
作者:linus linus系统创始人
解决的问题
代码版本管理
多人协作 编写项目
通俗来说
- 毕业论文初始版
- 毕业论文修改版
- 毕业论文最终版
安装网址:
傻瓜式安装,next的即可
注册gitee
Gitee - 基于 Git 的代码托管和研发协作平台
https://gitee.com/
二、创建项目
1、全局配置
gitconfig --global user.name "Your Name"
git config --global user.email"email@example.com"
2、核心概念
- 工作区(写代表的文件夹)
- 暂存盘(隐藏的文件夹)
- 版本库
- 分支
3、暂存盘
git add my.txt 添加my.txt 单个文件到暂存区
git add *.txt 添加txt后缀名到暂存区
git add . 添加任意文件到暂存区
git checkout xxx 从暂存盘取回到工作区
git checkout my.txt
git checkout *.txt
git checkout .
4、版本库
⭐必须先添加到暂存盘,再添加到版本库
- git add . 添加到暂存盘
- git commit -m" 提示语句”添加版本库
- git log 查看版本
- git reflog 查看相关版本切换到某个版本
- git reset --hard 版本号
三、时光穿梭机
git reset --hard 版本号
可以切换到不同版本
![](https://img-blog.csdnimg.cn/d5d1e1c28ff34bf5a3d4070c7963049d.png)
git reflog 查看相关历史记录
(可以看到你的历史记录,及你返回的的记录)
![](https://img-blog.csdnimg.cn/4a05936a4a114d4493aa14adac1b2155.png)
git log 查看记录(不含回退版本
![](https://img-blog.csdnimg.cn/1070f14f5ec24ad2bf86479ee495acd2.png)
每修改一次,如果你想记录下来
git add .
git commit -m "说明"
四、推送到远程
1、远程仓库
1、添加远程仓库
git remote add origin 仓库地址
2、添加到版本库
git add .
git commit -m "提示"
3、推送到远程
git push -u origin "master"
4、 第二次推送
git push origin "master"
2、推送到远程
1、git push-u origin "master"首次
2、git push origin "master"推送
3、git push-f origin "master"强制用本地替换远程
五、分支
1、分支的创建
查看分支
git branch 查看本地分支
git branch -r 查看远程分支
创建分支
git branch 分支名
切换分支
git checkout 分支名
切换并创建分支
git checkout -b 分支名
合并分支
git merge 分支名称
删除分支
git branch分支名-d
二、拉取远程分支
git fetch origin "zql”拉取远程
“zql”分支git checkout zql切换到本地zql分支
git pull origin "zql"拉取并合并到本地zql分支
3、克隆
![](https://img-blog.csdnimg.cn/156a0af762e3489b93dbf34b2663d834.png)
4、创建分支的步骤
![](https://img-blog.csdnimg.cn/68b030963a3e4fcba807bd5aa5106ba9.png)
![](https://img-blog.csdnimg.cn/bee24c53c3184bee93ed0accbcb49f1c.png)
![](https://img-blog.csdnimg.cn/7bb932987c5541e2a5e96585a56501da.png)
![](https://img-blog.csdnimg.cn/fed64ce37c5b4dc8a8842513b0916d5d.png)
![](https://img-blog.csdnimg.cn/4320f75f41f24a0eae59d1fbc7ec273d.png)
![](https://img-blog.csdnimg.cn/32454f4f6e994566aac4946b95b62faa.png)