【原创】关于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开发时,有三个概念需要知道,工作区,暂存区和版本库.工作区就是直接进行操作的地方,版本库是要将修改提交的地方,那么暂存区是干什么的呢?下面将对暂存区深入研究. 一.修改后能直接提交吗? 在 ...
随机推荐
- 【翻译】Flume 1.8.0 User Guide(用户指南) Sink
翻译自官网flume1.8用户指南,原文地址:Flume 1.8.0 User Guide 篇幅限制,分为以下5篇: [翻译]Flume 1.8.0 User Guide(用户指南) [翻译]Flum ...
- select下拉框左右变换
效果图: 使用jQuery插件---multiselect2side做法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ...
- 【js jQuery】map集合 循环迭代取值---以及 map、json对象、list、array循环迭代的方法和区别
后台给前台传来一个map @ResponseBody @RequestMapping(value = "getSys") public Map<Long,String> ...
- 实现PHP服务端和c#客户端数据交换
服务端实现功能1,数据库的访问dbhelper.php包括执行语句返回多行,返回json数据,返回单条记录,返回第一行第一列的整数,返回第一行第一列的浮点数,返回第一行第一列的双精度数,返回第一行第一 ...
- Python数据结构之单链表
Python数据结构之单链表 单链表有后继结点,无前继结点. 以下实现: 创建单链表 打印单链表 获取单链表的长度 判断单链表是否为空 在单链表后插入数据 获取单链表指定位置的数据 获取单链表指定元素 ...
- C语言常识
struct tree{ struct tree *left; struct tree *right; }; typedef struct tree newtree; int main(int arg ...
- noip第28课资料
- noip第24课资料
- Scala知识点汇总
Scala数组小结 1.定长数组 定长数组:指长度不可变的数组Array.第一种方式:先声明一个数组,后初始化该数组: scala> val array = new Array[Double]( ...
- linux-ssh登陆导语
用户登录前显示的导语信息(在你选择的文件中配置,例如 /etc/login.warn) 用户成功登录后显示的导语信息(在 /etc/motd 中配置) 如何在用户登录前连接系统时显示消息 当用户连接到 ...