【原创】关于Git暂存区的理解
关于Git暂存区的理解
git add <文件名>//将一个文件添加进暂存区
git hash-object <文件名>
git update-index <文件名>
#初始化仓库
$git init
Initialized empty Git repository in E:/t/test/.git/
#查看Git当前状态
$git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
#在当前目录下新建一个内容为"this is a test file"的test.txt
$echo 'this is a test file ,version 1'> test.txt
#再次查看Git的状态,Git会提示工作目录下有一个未跟踪的文件
$git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
#此时查看.git/objects目录,只有两个文件夹info和pack
$git hash-object -w test.txt
4617a36485976a90eb72e7020911dea0c892956b
#此时.git/objects目录下有了46子目录以及该子目录下17a36485976a90eb72e7020911dea0c892956b文件
#Git仍然显示test.txt为未跟踪文件
$git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
#将我们上次的test.txt添加进暂存区
$git add test.txt
#查看状态
$git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
#提交
git commit -m "add test.txt file ,version 1"
#查看当前状态,当前工作目录是干净的,没有什么要提交的了
#此时查看.git/objects目录,多了两个子目录,一个是tree对象,一个是commit对象暂时忽略它
$git status
On branch master
nothing to commit, working directory clean
#继续修改
$echo 'this is a test file ,version 2'> test.txt
#Git显示有一个修改文件未放入暂存区
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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
$git hash-object -w test.txt
1ed62f7cc06e6a57cdbaf9a5a5023aa93bd1ffb1
$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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
#创建一个new.txt新文件
$echo 'this is a new.txt file'> new.txt
#添加到暂存区并提交,此时可以看到提示信息中有master b5e4b5c,该数值为commit对象的SHA-1值
$git add new.txt
$git commit -m "add new.txt file"
[master b5e4b5c] add new.txt file
file changed, file insertion(+)
create mode new.txt
#通过cat-file命令可以查看对象中存储的内容,可以看到master commit对象指向的是一棵树对象,即代表根目录
$git cat-file -p b5e4b5c
tree 019ab86ed8f73265378a25dc00bff6c085f35cb0
parent 8d50d0c061da5104551bdbaa060e0d4c916411c1
author cposture <cposture@.com>+
committer cposture <cposture@.com>+
add new.txt file
#查看树对象根目录的存储内容,可以发现tree对象存储的是指向两个我们创建的文件SHA-1值和其他相关信息,而不是数据本省内容
$git cat-file -p 019ab86
blob 3e1267f7b311e69a691cf2ff5b90b46afaa1a359 new.txt
blob d5210ccb24bd6e8bbc994ade3be3b48a9001f3b7 test.txt
user.name 和user.email中获得)以及当前时间戳、一个空行,以及提交注释信息。

【原创】关于Git暂存区的理解的更多相关文章
- 第二节《Git暂存区》
在上一节中我们的demo版本库经历了一次提交,我们可以使用git og --stat查看一下提交日志. [root@git demo]# git log --statcommit 986a1bd458 ...
- Git学习之Git 暂存区
============================= 修改文件后是否可以直接提交 ============================ (1) 向文件中追加一行内容 $ echo &quo ...
- git 填坑之 git 暂存区忽略文件
今天修改公司项目文件的时候,发现被修改的文件的始终不显示已经被修改. 本来是想要把 KWh 改成 kWh,然后执行 git status 后,没有文件修改记录: 开始分析究竟是因为什么导致的这样诡异的 ...
- idea 编辑器Git暂存区的使用
平时在开发时候 一般线上环境和线下环境区别会很大,所以一下线下的自己测试环境的代码没有如果提交会影响线上环境,所以一般都会使用git的一个暂存区作为临时存放不需要提交的代码,这样每次提交代码都可以在不 ...
- Git学习笔记(2)——版本的回退,和暂存区的理解
本文主要记录了版本的回退,以及工作区,暂存区概念的理解. //开始之前,先回顾上次的内容,修改文件如下,并提交到版本库. Git is a distributed version control sy ...
- git学习(四):理解git暂存区(stage)
与一般的版本管理不同的是,git在提交之前要将更改通过git add 添加到暂存区才能提交(git commit).即使是已经交给了git来管理的文件也是如此.这里继续学习git的暂存区. 通过git ...
- git分布式版本控制系统权威指南学习笔记(二):git add暂存区的三个状态以及暂存区的理解
文章目录 不经过git add(到暂存区),能直接进行commit吗? 举个
- Git权威指南学习笔记(二)Git暂存区
例如以下图所看到的: 左側为工作区,是我们的工作文件夹. 右側为版本号库,当中: index标记的是暂存区(stage),所处文件夹为.git/index,记录了文件的状态和变更信息. master标 ...
- git暂存区
在使用git开发时,有三个概念需要知道,工作区,暂存区和版本库.工作区就是直接进行操作的地方,版本库是要将修改提交的地方,那么暂存区是干什么的呢?下面将对暂存区深入研究. 一.修改后能直接提交吗? 在 ...
随机推荐
- 87、代码适配IphoneX
一.APP在iphoneX运行后不能占满,上下都有多余的边 解决方法:把旧的image.xcassets中的LaunchImage删掉,重新创建并在Images.xcassets中为iPhone X添 ...
- 网页手机wap2.0网页的head里加入下面这条元标签,在iPhone的浏览器中页面将以原始大小显示,并不允许缩放
网页手机wap2.0网页的head里加入下面这条元标签,在iPhone的浏览器中页面将以原始大小显示,并不允许缩放. <meta name="viewport" conten ...
- golang使用 gzip压缩
golang使用 gzip压缩 这个例子中使用gzip压缩格式,标准库还支持zlib, bz2, flate, lzw 压缩处理_三步: 1.创建压缩文件2.gzip write包装3.写入数据 ou ...
- HTTP一、HTTP介绍与套接字
目录 一.套接字 1.HTTP与Apache 2.应用层协议:HTTP 3.套接字(IP+协议端口的组合) 4.套接字图示 5.套接字相关知识点 二.HTTP 一.套接字 1. ...
- spring aop 的代理工厂
参考 https://docs.spring.io/spring/docs/4.3.11.RELEASE/spring-framework-reference/htmlsingle/#aop-unde ...
- 初识 Proxysql
1.ProxySQL 介绍和安装 ProxySQL 是一种高性能.高可用的开源中间件,适用于mysql和相关的数据库,如MariaDB官网:http://www.proxysql.com 安装 发行版 ...
- Go的Get命令兼容公司Gitlab仓库的HTTP协议
对于公司的私有Gitlab仓库,没有对https支持,在使用最新版本的go get命令时,需要使用-insecure参数来支持http,但如果导入的包里边依赖了需要https的仓库,就不好使了,折腾了 ...
- python对象的for迭代实现
第一种:__iter__ 实现__iter__的对象,是可迭代对象.__iter__方法可以直接封装一个迭代器,从而实现for循环 class A: def __init__(self): self. ...
- Readme.txt
进入大学,越来越发现自学确实很重要,在学习计算机上,老师上课讲的远远不够,光凭理论是不够的.第一个接触的是VC++6.0这个老版的软件,一节理论课可以过三章内容着实惊吓,现在发现Vscode 可以将代 ...
- git无法同步
出现问题: fatal: destination path 'test' already exists and is not an empty directory. 解决方法如下: git init ...