写在前面:
我们之前的分享,讲了很多的git的分支管理。但是并没有讲git是如何完成一次提交的,以及对这些提交我们能做什么操作。现在很多同学都习惯使用svn,vscode的git插件来完成提交的操作。并不了解git具体做了什么。本次分享对pro git一书的学习。
image.png
状态与工作区域的概念
image.png
image.png
先认识一个命令:git status
用于查看处在各个状态的文件的整体情况
最基本的git操作
image.png
涉及命令:
git add hello.js
git commit -m "create hello.js"
操作流程:
-
使用
git status
查看项目整体状态, 发现一个新文件(新增修改状态)
image.png
-
使用
git add hello.js
或git add .
,已暂存
image.png
-
使用
git commit -m "create hello.js"
,已提交,形成一次提交记录
image.png
-
再来一次修改提交
image.png
针对已经提交的记录我们能做什么
- 查看提交记录
git log
image.png
- 比较两次提交的差异
git diff HEAD^ HEAD
image.png
- HEAD表示当前提交,HEAD表示上一次提交,HEAD^表示上上次...
- HEAD表示当前提交,HEAD~1表示上次,HEAD~2表示上上次
- 合并两次提交为一次
git rebase -i HEAD~2
image.png
image.png
image.png
image.png
image.png
看到这里,我们想知道原来的 "update hello.js again"的那次提交记录那里去了?
这次的"update hello.js"的提交记录跟上一次是同一个吗?
- 每一次当前HEAD发生改变(包括切换branch, pull, 添加新commit)一个新的纪录就会被添加到reflog.
-
使用
git reflog
查看所有引用操作
image.png
-
使用
git checkout -b again d7c05b1
创建一个新分支
image.png
-
使用
git log
查看提交记录,我们发现之前的提交记录又回来了
image.png
-
每次提交都在一条分支上,只不过有些有名字(master,develop),有些没有名字(d7c05b1)
master,develop,Tags,HEAD,d7c05b1都是某一次提交的引用指针。(当然,有些分支没有提交到远程)
image.png
image.png
-
理解这句话(当然更安全的是推送到远程)
image.png
git对象的概念


-
objects 对象存储每个文件的修改
image.png
image.png



Git引用(.git/refs中存放了git的引用,如tag,master, develop),引用是可以随便移动的

网友评论