【原创】关于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开发时,有三个概念需要知道,工作区,暂存区和版本库.工作区就是直接进行操作的地方,版本库是要将修改提交的地方,那么暂存区是干什么的呢?下面将对暂存区深入研究. 一.修改后能直接提交吗? 在 ...
随机推荐
- easyui_validatebox常用验证
$.extend($.fn.validatebox.defaults.rules, { idcard: {// 验证身份证 validator: function (value) { return / ...
- Redis的启动及配置
在redis已经安装完成的情况下,进入redis/bin目录下,输入命令: ./redis-server,就可以直接启动redis了,效果如图所示: 但是此时终端无法进行任何操作,按CTRL+c命令, ...
- Java集合不能存放基本数据类型
Java集合不能存放基本数据类型,只能存放对象的引用. 每个集合元素都是一个引用变量,实际内容都存放在堆内或方法区里面, 但是基本数据类型是在栈内存上分配空间的,栈上的数据随时会被收回. 如何解决? ...
- android与php使用base64加密的字符串结果不一样解决方法
base64将字符串转换为字节得到同一个值 一.错误 String signString = Base64.encodeToString(signContent.getBytes(),Base64.N ...
- 无网 离线状态下pip3安装 django等软件
https://stackoverflow.com/questions/7300321/how-to-use-pythons-pip-to-download-and-keep-the-zipped-f ...
- 使用idea搭建maven-web项目
使用idea搭建maven-web项目 1.用idea搭建项目:File--new--project 2.选择jdk版本,选择Maven-archetype-webapp来创建maven-web项目如 ...
- C#语法快速热身
if选择结构: 简单:if结构 单分子:If-else结构 多重:f-else-if结构 嵌套:if结构 语法: If(条件1){ If(条件2) }else{ } }else{ } Switch结构 ...
- 转 Tomcat+redis+nginx配置
为客户开发的一个绩效系统,采用了java web的开发方式,使用了一些spring mvc, mybatis之类的框架.相比于oracle ebs的二次开发,这种开发更加灵活,虽然和ebs集成的时候遇 ...
- ACM计划
原文 :http://027xbc.blog.163.com/blog/static/128159658201141371343475/ ACM主要是考算法的,主要时间是花在思考算法上,不是花在写程序 ...
- [转]Virtualization Basics
Virtualization Basics Virtualization is not a new concept, but its complexity has been growing, and ...