Git官网:https://git-scm.com/
概述
Git是一个开源的分布式版本控制系统。
目前最新版:2.21.0
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and multiple workflows.
安装
Windows系统在下面的地址下载完毕后
https://git-scm.com/download/win
按提示安装即可,一路默认配置就好
安装完毕后可以在cmd使用git命令
创建版本库
- 打开git Bash
- 进入合适的目录
- 通过mkdir创建合适的文件夹
- 通过cd进入你创建的目录
- 通过git init来把这个目录变成Git可以管理的目录
会出现如上提示~实际上生成了一个.git的隐藏文件夹
添加文件
- 使用 git add 来把文件添加到仓库
- 再用命令
git commit
把文件提交到仓库,后面还需要加上-m "说明信息"
好吧并不是很顺利,它竟然不知道我是谁?大雾
只好先按照提示告诉他我是谁了....
现在可以提交了吧~
基本操作
可以参考如下网站
https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80
https://www.runoob.com/git/git-basic-operations.html
https://www.liaoxuefeng.com/wiki/896043488029600/896954074659008
git status
修改文件内容再进行一次添加
提交再次查看状态
git diff
可以查看具体修改的内容
git log
提交日志
加上--pretty=oneline可以显示为一行(我寻思也不止一行啊?)
git reset --hard HEAD^ 回退上一版本 上上一个版本为HEAD^^ 上N个版本为HEAD~100
查看一下内容 (第一次提交的是空的)
git reset --hard commit_id 回退到指定id版本
这个id指的👇那个图里,(HEAD->)前面那一串黄色的字符
git reflog 查看命令历史
git checkout -- xxx
回到最近一次git commit或git add的状态
可以实现恢复误删文件的效果
git rm xxx
删除xxx文件
分支管理
默认会在master分支
git branch xx
创建分支xx
git checkout xx
切换到xx分支
git branch
查看当前分支
在分支中对test.txt进行修改
并添加提交
回到master 会发现内容并没有修改
git merge xxx
把xxx分支的成果合并到当前分支
再次进行查看,内容已经修改了
git branch -d xxx
删除xxx分支