Git study Note 2

Source: Internet
Author: User
Fifth: Understanding git objects and analyzing examples [root @ localhost ~] # Cdgit [root @ localhostgit] # mkdirobject [root @ localhostobject] # vimmain. cHellownayan! [Root @ localhostobject] # githash-objectmain.c calculates the hash value of main. c d32fe1_dc38cbfc7

 

Fifth:GitObject understanding and instance analysis

[Root @ localhost ~] #Cd/Git/

[Root @ localhost git] #MkdirObject

[Root @ localhost object] # vim main. c

 

Hello wnayan!

[Root @ localhost object] # git hash-object main. c // calculate the hash value of main. c

D32fe1_dc38cbfc7fe051a5d6dbae01551d8dbd

[Root @ localhost object] # git init

InitializEdEmpty Git repository in/git/object/. git/

[Root @ localhost object] # gitDd.

The following file (blob) is the file that saves the content of mia. c.

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

Total 8

-R -- 1 root 30 Nov 27 04:02 2fe1_dc38cbfc7fe051a5d6dbae01551d8dbd

[Root @ localhost object] # git commit-m "1st commint"

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

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

Create mode 100644 main. c

[Root @ localhost object] #Find. Git/objects/-type f // list common files in the folder

. Git/objects/AE/eedc3b20507db9600f7f72431557fcf9303252

. Git/objects/d3/2fe1_dc38cbfc7fe051a5d6dbae01551d8dbd

. Git/objects/da/97249d3649b1770b5cec8fa515833ea596f26f

[Root @ localhost object] # git show d32f // view blob content, which is the same as that of main. c.

Hello wnayan!

[Root @ localhost object] # gitCat-File-t aeeedc // the three statements are the object type.

TrEe

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

Commit

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

Blob

Of the above three objectsTreeSave the file name. blob stores the file content. This structure facilitates the storage of two files with the same content but different names (tree stores two names, and blob stores one copy of the content)

[Root @ localhost object] # gitLs-Tree aeee // lists the relationship between the tree and blob.

100644 blob d32fe1_dc38cbfc7fe051a5d6dbae01551d8dbd main. c

[Root @ localhost object] # git show-s -- pretty = raw da97 // view the commit content. The relationship is clear.

Commit da97249d3649b1770b5cec8fa515833ea596f26f

Tree aeeedc3b20507db9600f7f72431557fcf9303252

Author ethnicitybeta 1322337880 + 0800

Committer ethnicitybeta 1322337880 + 0800

 

1st commint

Sixth: multi-layer directory instances

[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 // view the generated object

. Git/objects/03/e86fb4437c4153cec24aa4021dca582abc0558

. Git/objects/56/2 f7710be64f9309a9fe6aa529753953dbe7e47

. Git/objects/20/6 ecf269d0f540995d88d6be825fecb09b5d3eb

. Git/objects/8f/006adb88a619f20442a9eb3148cff%91eaf0

. Git/objects/ba/2906d0666cf1_c7eaadd2cd3db615deDfDf3a

. Git/objects/90/48 a2fd8c21a70a2dffcf80c819eee2fb491a31

. Git/objects/a1/a869c8c840478164594a788ae5ce38dc0ee6da

[Root @ localhost wanyan] # git cat-file-t 03e8 // you can use thisCommandView object types in sequence

Tree

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

-Rw-r -- 1 root 23 Nov 27. git/HEAD // the currently used commit is the 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

The next step is to modify any file to generate a test of the multiple versions.

[Root @ localhost wanyan] # cd lib/

[Root @ localhost lib] # cat comment

Include

Change

[Root @ localhost wanyan] # git commit-a-m "2nd commit" // This command is a combination of the two Commands

[Master a7772df] 2nd commit

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

[Root @ localhost wanyan] # find. git/objects/-type f // you can find that the object is obviously increased.

. Git/objects/5f/eaaa33f5f3b3bc5fae0b750b2a5ebdc74b0a27

. Git/objects/03/e86fb4437c4153cec24aa4021dca582abc0558

. Git/objects/56/2 f7710be64f9309a9fe6aa529753953dbe7e47

. Git/objects/57/440 fcc9bc816076d418a2da304a2498b928bae

. Git/objects/20/6 ecf269d0f540995d88d6be825fecb09b5d3eb

. Git/objects/8f/006adb88a619f20442a9eb3148cff%91eaf0

. Git/objects/ba/2906d0666cf1_c7eaadd2cd3db615dedfdf3a

. Git/objects/90/48 a2fd8c21a70a2dffcf80c819eee2fb491a31

. Git/objects/a1/a869c8c840478164594a788ae5ce38dc0ee6da

. Git/objects/a7/772df6deb98005cf5ee21ae3ea863296677923

. Git/objects/2c/f3d62adf771c30fa8062ce2c491d14486ea5ee

The next step is to tag, which is divided into lightweight and fully contained

The first is lightweight tag. Although this tag is an object, it is not displayed in the object directory)

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

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

Total 8

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

[Root @ localhost wanyan] # cat. git/refs/tags/v1.0 // you can find that the content is commit.

A7772df6deb98005cf5ee21ae3ea863296677923

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

Commit

Then the fully-contained tag is displayed in the directory (object directory)

[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/2 f7710be64f9309a9fe6aa529753953dbe7e47

. Git/objects/57/440 fcc9bc816076d418a2da304a2498b928bae

. Git/objects/20/6 ecf269d0f540995d88d6be825fecb09b5d3eb

. Git/objects/8f/006adb88a619f20442a9eb3148cff%91eaf0

. Git/objects/ba/2906d0666cf1_c7eaadd2cd3db615dedfdf3a

. Git/objects/90/48 a2fd8c21a70a2dffcf80c819eee2fb491a31

. 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

Next, we will demonstrate how to use tags.

[Root @ localhost wanyan] # vi README // modify it

 

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!

The operation below demonstrates the status (before modification) of the tag, which is packaged out.

[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 // check whether a file in the tag status is found

Just test!

Conclusion: The concept of version control has been put into use before. The only concept of the term is svn, which has not been studied yet. It is very easy to use with git, here is a systematic learning record for use at work. I would like to thank Mr. Xiao Bu for his selfless teaching.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.