1. 克隆仓库到本地:git clone
- 首先准备好自己Gitee仓库的地址
![image-20221004132600110](https://img-blog.csdnimg.cn/img_convert/fe05084d42370912929b68d461cc5066.png)
$ git clone https://gitee.com/kongyan0410/code_for_-linux.git
- 输入Gitee的账号和密码
![image-20221004134554249](https://img-blog.csdnimg.cn/img_convert/85328b00503abde7a6c0cc4adbb5899f.png)
当出现这样,就是克隆完成,ll 命令可以看到我们克隆的仓库
![image-20221004132835557](https://img-blog.csdnimg.cn/img_convert/1b7f42a65b3bb1a9bba31c5b5c253bd3.png)
然后进入该仓库,ll 一下发现和我们新建的仓库中是一样的
![image-20221004132946512](https://img-blog.csdnimg.cn/img_convert/e51920a840d301eefc727eb47674205a.png)
2. 添加:git add
git add 你的文件 -> 预添加 文件到本地仓库(其实就是隐藏文件夹.git ) 注意是预添加
$ git add test.cpp
$ git add .
3. 提交:git commit
git commit -m "提交日志" :把文件提交到本地仓库
-m就是message,这个必须要添加,记录此次提交的信息(这次提交做了哪些改动)
$ git commit -m "这是一次测试"
第一次提交,此时可能会出现这样的情况
![image-20221004135843712](https://img-blog.csdnimg.cn/img_convert/1820b0bac174da8057109271af58648b.png)
出现的原因是建立仓库的时候信息不完善,让你完善一下自己的信息,方便git来追溯。
解决方法:
$ git config --global user.email "xxxxxx@xxx.com"
$ git confit --global user.name "xxxx"
注意:第一行是填写你的gitee绑定的邮箱
![image-20221004140224770](https://img-blog.csdnimg.cn/img_convert/591a37eb6071024c1436d2e5d5c3cde4.png)
第二行是你的gitee用户名,箭头位置才是用户名![image-20221004140150595](https://img-blog.csdnimg.cn/img_convert/6f25a1c5f6f80b4e00cf9621d9a34074.png)
此时,远端的云仓库和本地仓库是没有同步到
4. 推送:git push
把本地仓库中的内容,推送到云仓库
$ git push
![image-20221004140703579](https://img-blog.csdnimg.cn/img_convert/0d32c672eaa698bc760ae38947b5f6c6.png)
这样就是推送成功了
![image-20221004140813347](https://img-blog.csdnimg.cn/img_convert/ad55d4e7c974f5c3ce95ff57d1fe7b29.png)
5. 查看日志:git log
$ git log
![image-20221004141425150](https://img-blog.csdnimg.cn/img_convert/9844f93d52975af400dd463e80d06880.png)
6. 提交冲突问题
举个例子,A和B同时克隆了一个Gitee远程仓库,A提交并推送了一个文件testA.c,此时B也在写代码
B写完之后,想要提交一个testB.c,会发现此时提交被拒绝的情况
![image-20221004141913965](https://img-blog.csdnimg.cn/img_convert/a806dd2295a6ceec1372f0bfe3ebb758.png)
这是因为,B的本地仓库已经和远程仓库不同步了,就会发生提交冲突 问题。
解决方法:
$ git pull
然后再进行 git push即可
7. .gitignore文件配置
有时候我们不需要提交某些后缀的文件到我们的远程仓库,比如在Visual Stdio中除了我们自己建的.c、.cpp、.h文件 ,还会有.sln,.lib等文件 ,这时候就可以用.gitignore 文件把以这些为后缀的文件加入"黑名单",这样提交的时候,git就会自动忽略"黑名单"里的文件
下图是我的.gitignore 文件配置
![image-20221004142944180](https://img-blog.csdnimg.cn/img_convert/2e77a6847e8871380daa90568f11fed5.png)
8. 删除:git rm
如果想删除远程仓库中的文件
$ git rm *.c
$ git add .
$ git commit -m "删除test.c"
$ git push
注意:
git只会记录变化部分,每次提交的都是 变更
|