码迷,mamicode.com
首页 > 其他好文 > 详细

二、Git入门与基本使用(2)

时间:2019-03-15 23:08:50      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:html   otherwise   不同   proc   name   查看   lob   文件夹   文件的   

6、给文件重命名的简便方法

使用: git move 命令可以给暂存区中的文件重命名

$ git mv first.txt first.md

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        renamed:    first.txt -> first.md

$ git commit -m"move first.txt to first.md"
[master 5d63d93] move first.txt to first.md
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename first.txt => first.md (100%)

7、通过git log 查看版本演变历史

$ git log --oneline --graph        #图形化方式,简洁显示日志
* 7376bc5 (HEAD -> temp) Update fourth file
* 1d63ec8 Add fouth file
* b843c28 Add third file
* 0bd98cb Add second file
* c8588e4 Add first file

$ git log --oneline --graph --all    #显示所有分支日志
* 5d63d93 (master) move first.txt to first.md
* 7376bc5 (HEAD -> temp) Update fourth file
* 1d63ec8 Add fouth file
* b843c28 Add third file
* 0bd98cb Add second file
* c8588e4 Add first file

$ git log --oneline --graph --all -n3    #指定显示日志数量
* 5d63d93 (master) move first.txt to first.md
* 7376bc5 (HEAD -> temp) Update fourth file
* 1d63ec8 Add fouth file

8、.gitk:通过图形界面工具来查看版本历史
 gitk 是 git 提供的一个gui工具,可以很清晰地查看搜索提交历史及 git 相关操作。在终端 git 仓库目录下输入 gitk 命令即可使用。
技术图片

详细实用可参考连接:Use gitk to understand git

9、.git目录中各文件的含义

$ ls .git/ -l
total 14
-rw-r--r-- 1 nxf42573 1049089  27 Mar 15 17:46 COMMIT_EDITMSG
-rw-r--r-- 1 nxf42573 1049089 130 Mar 14 16:34 config
-rw-r--r-- 1 nxf42573 1049089  73 Mar 14 16:34 description
-rw-r--r-- 1 nxf42573 1049089 298 Mar 15 17:55 gitk.cache
-rw-r--r-- 1 nxf42573 1049089  21 Mar 15 17:50 HEAD
drwxr-xr-x 1 nxf42573 1049089   0 Mar 14 16:34 hooks/
-rw-r--r-- 1 nxf42573 1049089 369 Mar 15 17:50 index
drwxr-xr-x 1 nxf42573 1049089   0 Mar 14 16:34 info/
drwxr-xr-x 1 nxf42573 1049089   0 Mar 14 16:36 logs/
drwxr-xr-x 1 nxf42573 1049089   0 Mar 15 17:46 objects/
drwxr-xr-x 1 nxf42573 1049089   0 Mar 14 16:34 refs/

.git 文件的结构 The .git Directory
技术图片

文件 类型 内容 作用
config 文本文件 见上图 本地git存储库的配置文件
HEAD 文件夹 ref: refs/heads/master 当前分支,即 git branch 命令显示的分支
refs/heads 文件夹 - 本地库所有的分支
refs/heads/master 文本文件 6975b… master 分支最近一次 commit 的 SHA1 值
refs/heads/v1 文本文件 fd70… v1 分支最近一次 commit 的 SHA1 值
refs/remotes 文件夹 - refs/remotes目录下的所有内容都是对远程跟踪分支的提交的引用。
refs/remotes/origin 文件夹 - 远程存储库源的远程跟踪分支存储在这个目录中。
COMMIT_EDITMSG 文本文件 “some commit description” 最后一次 commit 的注释
hooks 文件夹 - 这个目录存放一些shell脚本,可以设置特定的git命令后触发相应的脚本
info 文件夹 - 包含git仓库的一些信息
logs 文件夹 - 保存所有更改的引用记录,继续打开logs文件夹,有refs文件夹和HEAD文件

10、commit、tree和blob三个对象之间的关系
git中文版
 每个对象(object) 包括三个部分:类型,大小和内容。大小就是指内容的大小,内容取决于对象的类型,有四种类型的对象:"blob"、"tree"、 "commit" 和"tag"。
 “blob”用来存储文件数据,通常是一个文件。
 “tree”有点像一个目录,它管理一些“tree”或是 “blob”(就像文件和子目录)
 一个“commit”只指向一个"tree",它用来标记项目某一个特定时间点的状态。它包括一些关于时间点的元数据,如时间戳、最近一次提交的作者、指向上次提交(commits)的指针等等。
Blob对象
 一个blob通常用来存储文件的内容,"blob对象"就是一块二进制数据,它没有指向任何东西或有任何其它属性,甚至连文件名都没有.因为blob对象内容全部都是数据,如两个文件在一个目录树(或是一个版本仓库)中有同样的数据内容,那么它们将会共享同一个blob对象。Blob对象和其所对应的文件所在路径、文件名是否改被更改都完全没有关系。
技术图片

$ git show 6ff87c4664
 Note that the only valid version of the GPL as far as this project
 is concerned is _this_ particular version of the license (ie v2, not
 v2.2 or v3.x or whatever), unless explicitly otherwise stated.
...

Tree 对象
 一个tree对象有一串指向blob对象或是其它tree对象的指针,它一般用来表示内容之间的目录层次关系。一个tree对象可以指向(reference): 一个包含文件内容的blob对象, 也可以是其它包含某个子目录内容的其它tree对象。 Tree对象、blob对象和其它所有的对象一样,都用其内容的SHA1哈希值来命名的;只有当两个tree对象的内容完全相同(包括其所指向所有子对象)时,它的名字才会一样,反之亦然。这样就能让Git仅仅通过比较两个相关的tree对象的名字是否相同,来快速的判断其内容是否不同。

$ git ls-tree fb3a8bdd0ce
100644 blob 63c918c667fa005ff12ad89437f2fdc80926e21c    .gitignore
100644 blob 5529b198e8d14decbe4ad99db3f7fb632de0439d    .mailmap
100644 blob 6ff87c4664981e4397625791c8ea3bbb5f2279a3    COPYING
040000 tree 2fb783e477100ce076f6bf57e4a6f026013dc745    Documentation
100755 blob 3c0032cec592a765692234f1cba47dfdcc3a9200    GIT-VERSION-GEN
100644 blob 289b046a443c0647624607d471289b2c7dcd470b    INSTALL
100644 blob 4eb463797adc693dc168b926b6932ff53f17d0b1    Makefile
100644 blob 548142c327a6790ff8821d67c2ee1eff7a656b52    README
...

Commit对象
"commit对象"指向一个"tree对象", 并且带有相关的描述信息。
技术图片

$ git show -s --pretty=raw 0bd98cb5d0d969cfc35
commit 0bd98cb5d0d969cfc35d8c5a16d33b5924cbc6b0
tree c1cf819308e03d9a2236f8ab2d0c7f5c6587d32f
parent c8588e43dd1053684632871fb8aec1945ee6a6ab
author Jone <764651475@qq.com> 1552553965 +0800
committer Jone <764651475@qq.com> 1552553965 +0800

    Add second file

 一个 tree对象: tree对象的SHA1签名, 代表着目录在某一时间点的内容.
 父对象 (parent(s)): 提交(commit)的SHA1签名代表着当前提交前一步的项目历史. 上面的那个例子就只有一个父对象; 合并的提交(merge commits)可能会有不只一个父对象. 如果一个提交没有父对象, 那么我们就叫它“根提交"(root commit), 它就代表着项目最初的一个版本(revision). 每个项目必须有至少有一个“根提交"(root commit). 一个项目可能有多个"根提交“,虽然这并不常见(这不是好的做法).
 作者 : 做了此次修改的人的名字, 还有修改日期.
 提交者(committer): 实际创建提交(commit)的人的名字, 同时也带有提交日期. TA可能会和作者不是同一个人; 例如作者写一个补丁(patch)并把它用邮件发给提交者, 由他来创建提交(commit).
 注释 用来描述此次提交.

二、Git入门与基本使用(2)

标签:html   otherwise   不同   proc   name   查看   lob   文件夹   文件的   

原文地址:https://blog.51cto.com/yinsuifeng/2363775

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!