Git是一个开源的分布式版本控制工具
配置身份
![](https://i-blog.csdnimg.cn/blog_migrate/5a4c2c635f1b13d842e1963b5633f1f0.webp?x-image-process=image/format,png/w/1240)
git config --global user.name "Tony"
git config --global user.email "tony@gmail.com"
检查是否配置成功
![](https://i-blog.csdnimg.cn/blog_migrate/f98c93502deee2c1c781114ce0cdb043.webp?x-image-process=image/format,png/w/1240)
git config --global user.name
git config --global user.email
创建本地代码仓库
![](https://i-blog.csdnimg.cn/blog_migrate/edace0d4473367c7f2beca157470a25e.webp?x-image-process=image/format,png/w/1240)
git init
仓库创建完成后会在项目目录下生成一个隐藏的.git文件夹 这个文件夹就是用来记录本地所有的Git操作的
如果你想要删除本地仓库 只需要删除这个文件夹就行
![](https://i-blog.csdnimg.cn/blog_migrate/47bcb8c39c45a9707316009e62267676.webp?x-image-process=image/format,png/w/1240)
提交本地代码
git add [提交的文件名] // 提交一个文件
git add . // 提交所有文件
![](https://i-blog.csdnimg.cn/blog_migrate/f91c1e5ebf99038a2b2cff97cbaeae17.webp?x-image-process=image/format,png/w/1240)
![](https://i-blog.csdnimg.cn/blog_migrate/d75bc8e74dfdb4a0051bfb7aa2d06074.webp?x-image-process=image/format,png/w/1240)
现在所有文件都加好了 然后用commit命令提交下
git commit -m "First commit."
忽略文件
在项目中创建 .gitignore 文件
在.gitignore文件下 每行指定的文件或目录会排除在版本控制外
![](https://i-blog.csdnimg.cn/blog_migrate/5b78046a5b93a89413384031b1529ef2.webp?x-image-process=image/format,png/w/1240)
查看修改内容
git status
![](https://i-blog.csdnimg.cn/blog_migrate/6b16dc2d9aa7efa4a0f32a21d0b34e6c.webp?x-image-process=image/format,png/w/1240)
查看更改内容
git diff
![](https://i-blog.csdnimg.cn/blog_migrate/acf60341815d5f1f66bef1da30827ba0.webp?x-image-process=image/format,png/w/1240)
撤销未提交的修改
git checkout
撤回提交
git reset
查看提交记录
git log
![](https://i-blog.csdnimg.cn/blog_migrate/9ca29d8f5b4dcd14df3a6b6f010c0eb4.webp?x-image-process=image/format,png/w/1240)
查看修改一行
git log 31f8f5c098c2b1988deea9a99a4511e35f85f0b6 -1
查看具体修改内容
git log 31f8f5c098c2b1988deea9a99a4511e35f85f0b6 -1 -p
查看分支
git branch
![](https://i-blog.csdnimg.cn/blog_migrate/b5afd612c79f8476dc8bab177e8c75ed.webp?x-image-process=image/format,png/w/1240)
建立分支
git branch version1.0
切换分支
git checkout version1.0
合并分支
git checkout master
git merge version1.0
删除分支
git branch -D version1.0
与远程版本库协作
git clone https://github.com/example/text.git
本地修改内容同步到远程版本库
git push origin master
远程版本库修改同步到本地
git fetch origin master
查看远程版本库修改了那些东西
git diff origin/master
之后在调用merge命令将origin/master分支上的修改合并到主分支上
git merge origin/master
pull命令是相当于 fetch和merge两个命令放在一起执行
git pull origon master