既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
新增文件
操作
vim hello.txt
#i 进入编辑模式
hello world
#wq保存并退出
再次查看本地库状态
(检测到未追踪的文件)
④添加暂缓区
基本语法:
git add 文件名称
查看状态
(检测到暂存区有新文件)
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: hello.txt
⑤提交本地库
将暂缓区
的文件提交到本地库
基本语法:
git commit -m "日志信息" 文件名
#没有文件需要提交
hasee@hasee MINGW64 /f/Git-space/git-demo (master)
$ git status
On branch master
nothing to commit, working tree clean
下一段实操案例:
#1.修改文件
vim hello.txt
hello world 1111 #追加内容
#2.查看状态(检测到工作区有文件被修改)
git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working
directory)
modified: hello.txt
#3.将修改的文件再次添加到暂缓区
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.
#4.查看状态(修改的文件已被提交到暂缓区
git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: hello.txt
2.2 版本相关操作
基本语法:
git reflog
查看版本信息git log
查看版本详细信git reset --hard 版本号
切换版本
#实操
git reflog #查看历史版本记录
3edd753 HEAD@{1}: commit: seconed time #3edd753 唯一版本标识号
a6e4928 (HEAD -> master) HEAD@{2}: commit (initial): This is my first commit file
#2.切换版本号
git reset --hard a6e4928
HEAD is now at a6e4928 This is my first commit file #HEAD指向a6e4928,提交信息--;
#3.再次查看版本信息 已移动至a6e4928该版本
git reflog
a6e4928 (HEAD -> master) HEAD@{0}: reset: moving to a6e4928 #重点看这
3edd753 HEAD@{1}: commit: seconed time
a6e4928 (HEAD -> master) HEAD@{2}: commit (initial): This is my first commit file
#4.可以查看该版本的文件有何不同
cat hello.txt #1.0版本
Git切换版本,底层其实就是移动head指针
,简单描述: head --> master --> first
三、分支
3.1 什么是分支?
在版本控制过程中,同时推进多个任务,为每个任务,我们就可以创建每个任务的单独 分支。使用分支意味着程序员可以把自己的工作从开发主线上分离开来,开发自己分支的时候,不会影响主线分支的运行。对于初学者而言,分支可以简单理解为副本,一个分支就是 一个单独的副本。(分支底层其实也是指针的引用)
3.2 分支的好处?
同时并行推进多个功能开发,提高开发效率。 各个分支在开发过程中,如果某一个分支开发失败,不会对其他分支有任何影响。失败的分支删除重新开始即可。
3.3分支的操作
命令名称 | 作用 |
---|---|
git branch 分支名 | 创建分支 |
git branch -v | 查看分支 |
git checkout 分支名 | 切换分支 |
git merge 分支名 | 把指定的分支合并到当前分支上 |
案例实操
1) 查看分支
基本命令:
git branch -v
$ git branch -v
* master 087a1a7 my third commit (*代表当前所在的分区)
2) 创建分支
基本命令:
git branch 分支名
hasee@hasee MINGW64 /f/Git-space/git-demo (master)
$ git branch demoBranch #创建分支
hasee@hasee MINGW64 /f/Git-space/git-demo (master)
$ git branch -v #查看分支
demoBranch a6e4928 This is my first commit file #刚创建的分支 并将主分支master的内容复制了一份
* master a6e4928 This is my first commit file
3) 修改分支
#在master分支下操作
vim hello.txt
#2.提交暂缓区
git add hello.txt
#3.提交本地库
git commit -m "GG" hello.txt
#4.查看分支
git branch -v
#运行结果
demoBranch a6e4928 This is my first commit file #没有改变
* master 4a8df47 GG #当前master分支已更新为最新一次提交的版本
#查看master分支的文件
cat hello.txt
3.4分支的合并
基本语法:
git merge 分支名称
实操:在master
分支上合并demoBranch
hasee@hasee MINGW64 /f/Git-space/git-demo (demoBranch)
$ git checkout master #切换分支
Switched to branch 'master'
hasee@hasee MINGW64 /f/Git-space/git-demo (master)
$ cat hello.txt #首先查看master分支下的文件内容
hello world
hello 0914
hasee@hasee MINGW64 /f/Git-space/git-demo (master)
$ git merge demoBranch #在Master分支下进行分支合并
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt #此时产生合并冲突
Automatic merge failed; fix conflicts and then commit the result.
hasee@hasee MINGW64 /f/Git-space/git-demo (master|MERGING)
$ cat hello.txt
hello world
<<<<<<< HEAD
hello 0914
=======
hello I'am demoBranch
>>>>>>> demoBranch
冲突产生:
形式上分支后跟MERGING,其原因是合并分支时,两个分支在同一个文件的同一个位置有两个完全不相同的修改,也就是内容,Git无法决定。必须人为确定
首先,进行查看状态,可以看到文件有两处修改
hasee@hasee MINGW64 /f/Git-space/git-demo (master|MERGING)
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
解决冲突问题:
编辑有冲突的符号,删除特殊符号,决定要修改的内容。
特殊符号:<<<<<<< HEAD 当前分支的代码 ======= 合并过来的代码 >>>>>>> demoBranch
hello world
hello 0914
hello I'am demoBranch
#2.添加暂缓区
git add hello.txt
#3.提交本地库 --发现后面 MERGING 消失,变为正常
git commit -m 'merge demoBranch'
![img](https://img-blog.csdnimg.cn/img_convert/da200685ef25ac70d3062f71dace684c.png)
![img](https://img-blog.csdnimg.cn/img_convert/e47e47d3be019400120bbd8f02b57d01.png)
![img](https://img-blog.csdnimg.cn/img_convert/7d80f3092adb6f1a70f584270c134409.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
[外链图片转存中...(img-yVo78gZh-1715044678693)]
[外链图片转存中...(img-DKZrZvkO-1715044678693)]
[外链图片转存中...(img-3GzqDTaV-1715044678693)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**