六、给文件重命名的简便方法html
使用: git move 命令能够给暂存区中的文件重命名git
$ 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%)
七、经过git log 查看版本演变历史shell
$ 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
八、.gitk:经过图形界面工具来查看版本历史
gitk 是 git 提供的一个gui工具,能够很清晰地查看搜索提交历史及 git 相关操做。在终端 git 仓库目录下输入 gitk 命令便可使用。less
详细实用可参考链接:Use gitk to understand gitide
九、.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 Directoryui
文件 | 类型 | 内容 | 做用 |
---|---|---|---|
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文件 |
十、commit、tree和blob三个对象之间的关系
git中文版
每一个对象(object) 包括三个部分:类型,大小和内容。大小就是指内容的大小,内容取决于对象的类型,有四种类型的对象:"blob"、"tree"、 "commit" 和"tag"。
“blob”用来存储文件数据,一般是一个文件。
“tree”有点像一个目录,它管理一些“tree”或是 “blob”(就像文件和子目录)
一个“commit”只指向一个"tree",它用来标记项目某一个特定时间点的状态。它包括一些关于时间点的元数据,如时间戳、最近一次提交的做者、指向上次提交(commits)的指针等等。
Blob对象
一个blob一般用来存储文件的内容,"blob对象"就是一块二进制数据,它没有指向任何东西或有任何其它属性,甚至连文件名都没有.由于blob对象内容所有都是数据,如两个文件在一个目录树(或是一个版本仓库)中有一样的数据内容,那么它们将会共享同一个blob对象。Blob对象和其所对应的文件所在路径、文件名是否改被更改都彻底没有关系。this
$ 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对象的名字是否相同,来快速的判断其内容是否不一样。3d
$ 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). 注释 用来描述这次提交.