既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
首次查看,工作区是没有什么文件的:
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use “git add” to track)
当我们新增了一个文件之后,再查看状态, 会检测到未追踪的文件:
$ git status
On branch master
No commits yet
Untracked files:
(use “git add …” to include in what will be committed)
hello.txt
nothing added to commit but untracked files present (use “git add”
to track)
---
#### 添加暂存区
git add 文件名
$ git add hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working
directory.
再次查看状态(检测到暂存区有新文件:)
$ git status
On branch master
No commits yet
Changes to be committed:
(use “git rm --cached …” to unstage)
new file: hello.txt
---
#### 提交本地库
git commit -m “日志信息” 文件名
$ git commit -m “my first commit” hello.txt
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working
directory.
[master (root-commit) 86366fa] my first commit
1 file changed, 16 insertions(+)
create mode 100644 hello.txt
再查看状态(没有文件需要提交):
$ git status
On branch master
nothing to commit, working tree clean
---
#### 修改文件
修改一下文件之后再查看状态:
$ git status
On branch master
Changes not staged for commit:
(use “git add …” to update what will be committed)
(use “git checkout – …” to discard changes in working
directory)
modified: hello.txt
no changes added to commit (use “git add” and/or “git commit -a”)
那么接下来就需要再次将修改的文件提交到暂存区,然后提交到本地仓库。
---
#### 查看历史版本
git reflog 查看版本信息
git log 查看版本详细信息
如果是想快速浏览版本信息,可以使用 reflog 即可,毕竟公司项目版本迭代信息可能已经很多了,想看详细日志也得看你有没有那个精力了。
$ git reflog
087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commit
ca8ded6 HEAD@{1}: commit: my second commit
86366fa HEAD@{2}: commit (initial): my first commit
---
#### 版本
以前我只知道版本回退,现在我知道原来还能向新。
git reset --hard 版本号
版本号是什么?版本号,查看一下日志就能看到了。
$ git reflog
087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commit
ca8ded6 HEAD@{1}: commit: my second commit
86366fa HEAD@{2}: commit (initial): my first commit
–切换到 86366fa 版本,也就是我们第一次提交的版本
$ git reset --hard 86366fa
HEAD is now at 86366fa my first commit
–切换完毕之后再查看历史记录,当前成功切换到了 86366fa 版本
$ git reflog
86366fa (HEAD -> master) HEAD@{0}: reset: moving to 86366fa
087a1a7 HEAD@{1}: commit: my third commit
ca8ded6 HEAD@{2}: commit: my second commit
86366fa (HEAD -> master) HEAD@{3}: commit (initial): my first commit
–然后查看文件 hello.txt,发现文件内容已经变化
Git 切换版本,底层其实是移动的 HEAD 指针。
---
### Git 分支操作
![在这里插入图片描述](https://img-blog.csdnimg.cn/2d426b9509e544ab8bd19411b661f8c7.png)
在版本控制过程中,同时推进多个任务,为每个任务,我们就可以创建每个任务的单独分支。使用分支意味着程序员可以把自己的工作从开发主线上分离开来,开发自己分支的时候,不会影响主线分支的运行。对于初学者而言,分支可以简单理解为副本,一个分支就是一个单独的副本。(分支底层其实也是指针的引用)
![在这里插入图片描述](https://img-blog.csdnimg.cn/4bfcabdc1eda455cb294cb4eae2db77b.png)
#### 分支基本操作
![在这里插入图片描述](https://img-blog.csdnimg.cn/8eebb390f97840e39c0050f50afd05bd.png)
#### 查看分支
小伙子,不要一上来就想着创建分支嘛。先看看前辈们已经达到了哪个高度了嘛。
git branch -v
$ git branch -v
- master 087a1a7 my third commit (*代表当前所在的分区)
---
#### 创建分支
git branch 分支名
$ git branch hot-fix
$ git branch -v
hot-fix 087a1a7 my third commit (刚创建的新的分支,并将主分支 master
的内容复制了一份)
- master 087a1a7 my third commit
---
#### 分支开发
接下来就可以在分支上进行开发了,开发完之后记得将代码提交到本地仓库。
---
#### 切换分支
git checkout 分支名
$ git checkout hot-fix
Switched to branch ‘hot-fix’
–发现当先分支已由 master 改为 hot-fix
---
#### 合并分支
git merge 分支名
这里有个要注意的点:不仅是可以把旁支合并到主支上,主支也可以被合并到分支上,分支之间也可以互相合并。
反正你爱怎么玩怎么玩,都是在你本地仓库上,又没有推送到远程仓库。
那现在我们想把旁支合并到主支上要怎么做呢?
1、切换到主支
2、git merge 旁支名
这样就万事大吉了吗?不一定的。脑子清醒的话很容易想到一个问题:主支修改了一个文件,分支也修改了同一个文件,现在以谁的为准?
脑子更清醒的人就要说了:你傻呀,我 clone 下来就切到分支去操作了,在我本地仓库我又不会去动主支的。
脑子再清醒一点的人已经懒的跟他说了:大哥,咱这是团队开发,咱的本地仓库早晚是都要合并到主线上的。
---
#### 合并冲突解决
冲突产生的表现:后面状态为 MERGING
打开冲突文件可以看到冲突的地方:
hello git! hello atguigu!
<<<<<<< HEAD
hello git! hello atguigu! master test
hello git! hello atguigu!
hello git! hello atguigu!
hello git! hello atguigu! hot-fix test
hot-fix
HEAD 到 === 的部分是主支的,后面是 hot-fix 的
冲突产生的原因:
合并分支时,两个分支在同一个文件的同一个位置有两套完全不同的修改。Git 无法替我们决定使用哪一个。必须人为决定新代码内容。
解决办法:
1、删掉冲突中不要的部分,留下最终的部分
2、git add 添加到暂存区
3、 git commit -m 注意,此时的 commit 后面不能带文件名。带文件名是几个意思呢?到底用哪个呢?
然后就会发现合并成功了。
---
### Git 团队协作机制
#### 团队协作
![在这里插入图片描述](https://img-blog.csdnimg.cn/56927decc9604f39973d8e238a692d79.png)
![img](https://img-blog.csdnimg.cn/img_convert/8821073dcc37e69ae7eaca422c45317a.png)
![img](https://img-blog.csdnimg.cn/img_convert/77f6cde9f98d06b37601951c425e5e0d.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以添加戳这里获取](https://bbs.csdn.net/topics/618668825)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
#### 团队协作
![在这里插入图片描述](https://img-blog.csdnimg.cn/56927decc9604f39973d8e238a692d79.png)
[外链图片转存中...(img-SnOeaLzM-1715826791648)]
[外链图片转存中...(img-VYyeEhu1-1715826791648)]
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化的资料的朋友,可以添加戳这里获取](https://bbs.csdn.net/topics/618668825)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**