Some basic git concepts

Source: Internet
Author: User
Tags commit hash sha1 tag name using git

1.Git Version Library

Git repository (repository) is just a simple database that contains all the information needed to maintain and manage revisions and histories of the project, andgit not only provides a complete copy of all the files in the repository, but also a copy of the repository itself.

When you clone or copy a repository to another repository, theconfiguration values for each repository, such as the username and email address, will be transferred together.

In the repository, GIT maintains two primary database structures: Object libraries and indexes.

1.1Git Object Type

The object library is the heart of the Git repository, and there are only 4 types of objects that Git puts in the object library:

① block (BLOB): each version of a file represents a blob.

② Tree: A directory tree object represents a layer of directory information, and git tracks the path name of a file through a directory tree object.

$ git write-tree #捕获索引状态并把它保存到一个树对象里

$ git ls-files-s #查看索引里的文件关联

#注意: The SHA1 value with the same directory tree object is identical.

#以下说明目录树的用法:

#创建一个新目录 and added to the index:


#生成提交树, 4a8b25 ... is the SHA1 value of this directory tree object


#此时, you can submit some information to the repository through the directory tree. Of course, usually not so troublesome, as long as git commit.

#查看提交对象的信息

③ commit: A Commit object holds metadata for each change in the repository.

④ Tags: a Label object assigns an arbitrary and human-readable name to a particular object.

The labels are divided into two categories:

① Lightweight

Just a reference to the Commit object, and these tags do not create permanent objects in the repository.

② with notes.

Git thinks the tagged tag is a "permanent" object.

#可以通过git the tag command to create a label with a commit message, a note, and an unsigned

$git tag-m "tag version 1.0" V1.0 object reference tag (40 bit that)

#如下所示, you can see the SHA1 value of a tagged object using git rev-parse tag name.


1.2. Index

The index describes the entire repository's directory structure, which captures a version of the overall structure of the project at some point in time. One of the key features of Git is that it allows you to use structured, well-defined steps to change the content of the index. The so-called index is a version of the file that you add to the cache after you use git add file, and you can stage changes (that is, add, delete, or edit a file or some files) through the git command and the index will record and save the changes until you are ready for git commit. The path name of the index trace file and the corresponding BLOB.

1.3Git Tracking Content

The first thing to note is that. git tracks content instead of files, and git doesn't track filenames or directory names that are related to files. if the contents of the two files are exactly the same, Git saves only one copy of the content in the Blob form in the object library, and the file has a unique SHA1 value. The contents of the file change, then Git calculates a new SHA1 value, identifies that it is now a different BLOB object and adds the Blob object to the object library. Because Git uses the full content hash value of a file as the file name, all of it must operate on a full copy of each file. The SHA1, hash code, and object ID that git users refer to are the same thing. On the Internet, files or blobs of any size can be judged by just comparing their SHA1 identifiers.

1.4 Packaging files

Not every time git modifies a file, it completely stores the entire contents of the two versions of the file, but instead uses a storage mechanism called packaged files . To create a packaged file, Git locates all files with very similar content, stores the entire content for one of them, and then calculates the differences between similar files and stores only the differences.

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.