良许Linux教程网 Git教程 Linux命令-git教程(二)

Linux命令-git教程(二)

上一篇介绍了git是什么,git的下载及安装,还有git的基本配置,这篇文章和大家深入讲解一下git

Linux命令-git教程(二)

第五:对于git对象的理解和实例分析

[root@localhost ~]# cd /git/

[root@localhost git]# mkdir object

[root@localhost object]# vim main.c

 

Hello wnayan!

[root@localhost object]# git hash-object main.c   //计算main.c的哈希值

d32fe487dc38cbfc7fe051a5d6dbae01551d8dbd

[root@localhost object]# git init

Initialized empty Git repository in /git/object/.git/

[root@localhost object]# git add .

以下这个文件(blob)就是保存mia.c内容的文件

[root@localhost object]# ll .git/objects/d3/

total 8

-r–r–r– 1 root root 30 Nov 27 04:02 2fe487dc38cbfc7fe051a5d6dbae01551d8dbd

[root@localhost object]# git commit -m “1st commint”

[master (root-commit) da97249] 1st commint

files changed, 1 insertions(+), 0 deletions(-)

create mode 100644 main.c

[root@localhost object]# find .git/objects/ -type f  //列出文件夹下的普通文件

.git/objects/ae/eedc3b20507db9600f7f72431557fcf9303252

.git/objects/d3/2fe487dc38cbfc7fe051a5d6dbae01551d8dbd

.git/objects/da/97249d3649b1770b5cec8fa515833ea596f26f

[root@localhost object]# git show d32f  //查看blob的内容,就是main.c的一样的内容

Hello wnayan!

[root@localhost object]# git cat-file -t aeeedc   //这三句是查看object的类型

tree

[root@localhost object]# git cat-file -t da97

commit

[root@localhost object]# git cat-file -t d32f

blob

以上三种对象中tree保存文件的名字,blob保存文件的内容,这种结构有利于两个内容相同但是名字不同的文件的保存(tree保存两个名字,blob保存一份内容就可以了)

[root@localhost object]# git ls-tree aeee   //列出tree和blob的对应关系

100644 blob d32fe487dc38cbfc7fe051a5d6dbae01551d8dbd      main.c

[root@localhost object]# git show -s –pretty=raw da97  //查看commit的内容,关系很明确

commit da97249d3649b1770b5cec8fa515833ea596f26f

tree aeeedc3b20507db9600f7f72431557fcf9303252

author ethnicitybeta 1322337880 +0800

committer ethnicitybeta 1322337880 +0800

 

1st commint

第六:多层目录的实例

[root@localhost /]# mkdir -p /git/wanyan

[root@localhost /]# cd /git/wanyan/

[root@localhost wanyan]# cat README

just test!

[root@localhost wanyan]# cat lib/comment

include

[root@localhost wanyan]# cat lib/include/main.c

main

[root@localhost wanyan]# git init

Initialized empty Git repository in /git/wanyan/.git/

[root@localhost wanyan]# git add .

[root@localhost wanyan]# git commit -m “1st version”

[master (root-commit) 206ecf2] 1st version

3 files changed, 3 insertions(+), 0 deletions(-)

create mode 100644 README

create mode 100644 lib/comment

create mode 100644 lib/include/main.c

[root@localhost wanyan]# find .git/objects/ -type f  //查看生成的对象

.git/objects/03/e86fb4437c4153cec24aa4021dca582abc0558

.git/objects/56/2f7710be64f9309a9fe6aa529753953dbe7e47

.git/objects/20/6ecf269d0f540995d88d6be825fecb09b5d3eb

.git/objects/8f/006adb88a619f20442a9eb3148cff31691eaf0

.git/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a

.git/objects/90/48a2fd8c21a70a2dffcf80c819eee2fb491a31

.git/objects/a1/a869c8c840478164594a788ae5ce38dc0ee6da

[root@localhost wanyan]# git cat-file -t 03e8  //可以通过这个命令依次查看对象的类型

tree

[root@localhost wanyan]# ll .git/HEAD

-rw-r–r– 1 root root 23 Nov 27 04:23 .git/HEAD  //当前使用的commit是master

[root@localhost wanyan]# cat .git/HEAD

ref: refs/heads/master

[root@localhost wanyan]# cat .git/refs/heads/master

206ecf269d0f540995d88d6be825fecb09b5d3eb

[root@localhost wanyan]# git cat-file -t 206e

commit

接下来就是修改任意的文件,来生成第多个版本的测试

[root@localhost wanyan]# cd lib/

[root@localhost lib]# cat comment

include

change

[root@localhost wanyan]# git commit -a -m “2nd commit”  //这个命令是那两个命令的综合

[master a7772df] 2nd commit

1 files changed, 1 insertions(+), 0 deletions(-)

[root@localhost wanyan]# find .git/objects/ -type f   //可以发现对象明显的增加

.git/objects/5f/eaaa33f5f3b3bc5fae0b750b2a5ebdc74b0a27

.git/objects/03/e86fb4437c4153cec24aa4021dca582abc0558

.git/objects/56/2f7710be64f9309a9fe6aa529753953dbe7e47

.git/objects/57/440fcc9bc816076d418a2da304a2498b928bae

.git/objects/20/6ecf269d0f540995d88d6be825fecb09b5d3eb

.git/objects/8f/006adb88a619f20442a9eb3148cff31691eaf0

.git/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a

.git/objects/90/48a2fd8c21a70a2dffcf80c819eee2fb491a31

.git/objects/a1/a869c8c840478164594a788ae5ce38dc0ee6da

.git/objects/a7/772df6deb98005cf5ee21ae3ea863296677923

.git/objects/2c/f3d62adf771c30fa8062ce2c491d14486ea5ee

接下来这个步骤就是来打tag,tag分为轻量级的和全面包含的

首先是轻量级的tag这个tag虽然是对象,但是并不在对象目录里显示(object目录)

[root@localhost wanyan]# git tag v1.0

[root@localhost wanyan]# ll .git/refs/tags/

total 8

-rw-r–r– 1 root root 41 Nov 27 04:50 v1.0

[root@localhost wanyan]# cat .git/refs/tags/v1.0   //可以发现内容是commit呀

a7772df6deb98005cf5ee21ae3ea863296677923

[root@localhost wanyan]# git cat-file -t a777

commit

然后是全面包含的tag,目录里显示(object目录)

[root@localhost wanyan]# git tag -a stable1.0 -m “1st stable”

[root@localhost wanyan]# find .git/objects/ -type f

.git/objects/5f/eaaa33f5f3b3bc5fae0b750b2a5ebdc74b0a27

.git/objects/03/e86fb4437c4153cec24aa4021dca582abc0558

.git/objects/56/2f7710be64f9309a9fe6aa529753953dbe7e47

.git/objects/57/440fcc9bc816076d418a2da304a2498b928bae

.git/objects/20/6ecf269d0f540995d88d6be825fecb09b5d3eb

.git/objects/8f/006adb88a619f20442a9eb3148cff31691eaf0

.git/objects/ba/2906d0666cf726c7eaadd2cd3db615dedfdf3a

.git/objects/90/48a2fd8c21a70a2dffcf80c819eee2fb491a31

.git/objects/a1/a869c8c840478164594a788ae5ce38dc0ee6da

.git/objects/a7/772df6deb98005cf5ee21ae3ea863296677923

.git/objects/8a/26be084ddce5e8178ca91def21e0c8f7a0945e

.git/objects/2c/f3d62adf771c30fa8062ce2c491d14486ea5ee

[root@localhost wanyan]# git cat-file -t 8a26

Tag

接下来演示tag的使用

[root@localhost wanyan]# vi README   //修改一下

 

just test!

another hang!

[root@localhost wanyan]# git commit -a -m “3rd commit”

[master a08fc01] 3rd commit

1 files changed, 1 insertions(+), 0 deletions(-)

[root@localhost wanyan]# cat README

just test!

another hang!

下边的操作演示的是把tag那个状态(修改之前),那个打包出去

[root@localhost wanyan]# git archive –format=tar –prefix=wanyan/ v1.0 | gzip > /tmp/wanyan.tar.gz

[root@localhost wanyan]# cd /tmp/

[root@localhost tmp]# tar zxvf wanyan.tar.gz

wanyan/

wanyan/README

wanyan/lib/

wanyan/lib/comment

wanyan/lib/include/

wanyan/lib/include/main.c

[root@localhost tmp]# cd wanyan

[root@localhost wanyan]# cat README   //是不是发现又是tag那个状态的文件

just test!

以上就是良许教程网为各位朋友分享的Linux系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你!

良许微信公众号

本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部