1.下载安装Git(略)
2.打开git bash窗口
3.查看版本号、设置用户名和邮箱
用户名和邮箱可以随意起,与GitHub的账号邮箱没有关系

4.初始化git
在D盘中新建gitspace文件夹,并在该目录下打开git bash窗口
git init
初始化完成后会在该目录下创建.git文件,此文件为隐藏文件,用可用ll -a命令查看

5.查看本地库状态
git status
由于目录下没有文件,查看本地库状态时显示nothing to commit
用vim编辑一个hello.txt文件


再次查看本地库状态,提示Untracked files,表示目录下有未被追踪的文件
用git add hello.txt命令使hello.txt文件添加至暂存区
接着再查看本地库状态,提示文件可提交至本地库

将文件从暂存区中删除git rm --cached hello.txt
可以看到只是将暂存区的文件删掉,而本地磁盘中的文件任然存在
再次查看本地库状态,hello.txt文件又变成未追踪状态

再次添加hello.txt文件至暂存区,这次将文件提交至本地库,并查看本地库状态
git add hello.txt
git commit -m "first commit" hello.txt

此时已将hello.txt成功提交至本地库,并且可以查看日志
git reflog
git log
reflog为精简日志
log为详细日志

如果再次修改hello.txt文件,查看本地库状态,hello.txt又变成为追踪状态
再次将文件添加至暂存区并提交至本地库

查看日志,之前一个版本现在变为了两个

版本穿梭(回到指定版本)
使master指向指定的版本地址,比如说想穿梭到第一次commit的版本
git reset --hard 4dcbaf8

6.git分支
查看分支 git branch -v
创建新的分支 git branch hot-fix
跳转分支 git checkout hot-fix

在hot-fix分支下修改hello.txt

查看日志,HEAD指向hot-fix
切换至master分支,master分支下的hello.txt并未改变

合并分支
git merge hot-fix

此时master下的hello.txt已被修改

合并冲突,如果master和hot-fix分支同时修改文件并提交至本地库,用普通合并会报错
首先在master分支下在最后第二行添加master test,并提交

切换至hot-fix分支在最后一行添加hot-fix test,并提交

切换至master分支合并hot-fix
git merge hot-fix

查看状态,显示master分支正在合并中
进入hello.txt文件并编辑,将不需要的内容删除
提交时不需要指定文件名,因为两个分支都修改了hello.txt,如果带文件名会报错,系统不知道要提交哪个hello.txt

此时再查看文件已经修改成功
