1.git的基础概念
在 Git 中的绝大多数操作都只需要访问本地文件和资源,一般不
需要来自网络上其它计算机的信息。
特性:
① 断网后依旧可以在本地对项目进行版本管理
② 联网后,把本地修改的记录同步到云端服务器即可
使用 Git 管理的项目,拥有三个区域,分别是工作区、暂存区、Git 仓库。
![](https://img-blog.csdnimg.cn/img_convert/15143a956f49e3960f178622997094f5.png)
![](https://img-blog.csdnimg.cn/img_convert/fa59c357c4593250d4bb3be0bb1a49c5.png)
2.初始化仓库 git init
如果自己有一个项目目录,想要用 Git 来控制它,需要执行如下两个步骤:
① 在项目目录中,通过鼠标右键打开“Git Bash”
② 执行 git init 命令将当前的目录转化为 Git 仓库
git init 命令会创建一个名为 .git 的隐藏目录,这个 .git 目录就是当前项目的 Git 仓库,里面包含了初始的必要文件,这些文件是 Git 仓库的必要组成部分。 这个文件被删除了就相当于退出了git库。
3. 查看文件的状态 git status
![](https://img-blog.csdnimg.cn/img_convert/3781e952247565701c1ff33191b0e198.png)
在状态报告中可以看到新建的 index.html 文件出现在 Untracked files(未跟踪的文件) 下面。
未跟踪的文件意味着 Git 在之前的快照(提交)中没有这些文件;Git 不会自动将之纳入跟踪范围,除非明确
地告诉它“我需要使用 Git 跟踪管理该文件”。
但是使用 git status 输出的状态报告很详细,但有些繁琐。
使用git status -s 就能以精简的方式输出结果
![](https://img-blog.csdnimg.cn/img_convert/ad0bb3f8d503d25f5c32312fbbea4775.png)
4.添加新文件到 git add (后面跟文件名)
![](https://img-blog.csdnimg.cn/img_convert/614b5091f19c1c9769cfaa1078e42866.png)
4.1 一次性添加多个文件 git add .
![](https://img-blog.csdnimg.cn/img_convert/7b6f0295c46874d69f498320662e8668.png)
5.提交文件 git commit -m
![](https://img-blog.csdnimg.cn/img_convert/509680719c0004efe8a14c13eeef1f5a.png)
![](https://img-blog.csdnimg.cn/img_convert/45659ed45b3e6146aca86f133c2dc5c7.png)
6.对已提交的文件进行修改
![](https://img-blog.csdnimg.cn/img_convert/e93606f30acf0a5bb041a572383dd0bd.png)
7.暂存已修改的文件
![](https://img-blog.csdnimg.cn/img_convert/a60631fcc5441f4e504f5147b3b7fa92.png)
8.提交暂存的文件
![](https://img-blog.csdnimg.cn/img_convert/3569f03a4f486a0859d85fc8f259122d.png)
9.撤销对文件的修改
![](https://img-blog.csdnimg.cn/img_convert/f59099c16229cf24f2ef741a680778a9.png)
10.取消暂存的文件
![](https://img-blog.csdnimg.cn/img_convert/49148ddebb35320cbbc4afeabea7061e.png)
11.跳过暂存区域 直接提交文件 git commit -a -m “描述信息”
![](https://img-blog.csdnimg.cn/img_convert/15ed5a095ffb7cac142c2d9776154141.png)
12.移除文件
![](https://img-blog.csdnimg.cn/img_convert/d7a81d1e876010428acd49e2ea7d1424.png)
13.忽略文件
![](https://img-blog.csdnimg.cn/img_convert/36b4a4912b34f2b703b18f9abf0c8fb1.png)
14.glob模式
![](https://img-blog.csdnimg.cn/img_convert/dbeef18fd14a3bb82dd922ba488afba6.png)
15. .gitignore 文件的例子
![](https://img-blog.csdnimg.cn/img_convert/2b9269d637e5660630c0620239b8e45b.png)
16.查看提交历史
![](https://img-blog.csdnimg.cn/img_convert/d0364f586c072091d270b1429b103cf4.png)
17.回退到指定版本
![](https://img-blog.csdnimg.cn/img_convert/5e8a1325853d4a4ad647e320eaba9e9c.png)
总结:(重点使用)
初始化 Git 仓库的命令
git init
查看文件状态的命令
git status 或 git status -s
一次性将文件加入暂存区的命令
git add .
将暂存区的文件提交到 Git 仓库的命令
git commit -m "提交消息"