Part1 基础概念
git作用:管理代码版本,记录,切换,合并代码
git仓库:记录文件状态内容和历史记录的地方(.git文件夹)
git的三个区域:1)工作区:实际开发时的文件夹;2)暂存区:暂存改动过的文件;3)版本库:提交并保存暂存区中的内容

git文件状态:未跟踪(未被git管理过)、已跟踪(新添加、未修改、已修改)
Part2. 本地仓库
- 配置Git
当安装Git后⾸先要做的事情是设置你的用户名称和e-mail地址
bash
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
查看是否配置成功
bash
git config -l
2.将本地文件夹变成git仓库
(记得要切换到自己的项目文件夹里再init)
3.暂存指定文件
bash
git add 文件名
文件名如果有路径是相对路径,如果暂存所有的文件用.代替
bash
git ls-files #查看当前暂存区的文件
4.提交到版本库
bash
git commit -m "注释说明"

Part3 暂存区的使用
暂存区覆盖工作区:
bash
git restore 文件名
移除暂存区文件:
bash
git rm --cache 文件名
git ls-files #查看当前暂存区的文件
Part4 回退版本
Git回退版本:把版本库某个版本对应的内容快照,恢复到工作区/暂存区
查看历史提交:
bash
git log --oneline

回退的三种方式:
bash
git reset --soft/--hard/--mixed 版本号

回退后查看日志,会是截止到当前版本的日志,如果需要查看完整日志使用git reflog --oneline
Part 5 忽略文件
让git忽略一些文件的跟踪,如npm下载的第三方包,vscode配置文件,运行时生成的日志文件、临时文件等。
在项目根目录新建.gitignore文件,填入相应的配置来忽略指定文件
Part6 分支
使用场景:开发新的需求,保证主线代码随时可用,多人协同开发;或者单独创建分支修复bug

创建新的分支
bash
git branch 分支名
让指向master的head指针,来指向新创建的分支
bash
git checkout 分支名

往新分支添加代码,更新提交版本
分支的合并与删除
切换回要合如的主分支:
bash
git checkout master
合并其他分支过来
bash
git merge bug
删除合并后的分支
bash
git branch -d bug

合并冲突
不同分支中,对同一文件的同一部分修改,git合并会产生冲突。
解决办法:和组员协商后再决定保留哪个,手动解决后再提交一次合并

常用命令
最后,附上git常用命令,人老了,老是容易忘记
