Git opening my notes - the basic concepts

Taking advantage of the New Year, I learned the content before Git good order a bit, ready to write a few blog about Git, one can deepen my understanding of Git, we also hope to help needy junior partner. When I was using Git tools, often encounter the following concepts: warehouses, references, workspace objects. These concepts can be said is the core point of learning Git, as long as these concepts to figure out, using Git behind every step of the operation will become very clear. Here I talk from a few basic concepts, in simple terms can be summarized in one sentence: a warehouse, two references, three workspace the four objects.

Warehouse (Repository) , also known as the repository is where we store the final document is divided into local and remote warehouse warehouse.

 

Three Workspace 1.1

The nature of Git is a content-addressable file system. Git into the working directory, staging area, and the three major repository workspace.

Working directory , also known as the workspace, is the area of practical user file, there are two states in the document workspace: untracked (untracked) and has been traced (tracked). If the workspace file is modified, but not added to the staging area, it will not be submitted to the repository.

Staging area , located in the repository are actually contains a file index (establish a link between the object library files and objects) of the directory tree, we modify the contents of the file are not saved to the region, it records the file name and file status information (a time stamp, file length, etc.).

Repository , the region file has three states: modified (modified), it has been staging (staged), has been submitted (committed).

 

1.2 Git Object Model

There are four git object model, respectively, blob, tree, commit, tag. git using the SHA-1 algorithm to the content data object as input, generates a 40-character string as the identifier of the object. For example, do the same file has been modified to resubmit, git is to compare the contents of two submitted by comparing the SHA-1 value.

git cat-file [-tp] SHA-1  #查看git对象使用命令,参数t表示查看对象类型,p表示查看对象内容

the blob for storing file data, typically a document. View the blob content can also use the command

git show SHA-1

object tree , is a string point or other blob object tree pointer. Its role is similar to the directory and allows you to manage blob and tree objects, representing the contents of the directory tree, the relationship between the hierarchical directory contents. View tree object content can also use the following command

git ls-tree SHA-1
git cat-file -p master^{tree}
git show SHA-1

commit object , a tree used to point to an object, the object of a tree, parent, author, the submitter composition. A specific point of time a marker project. Note: a commit itself does not contain any information on what had been done to modify its description, and all changes are submitted by comparison with a parent come. Index to submit commit object using the git commit command to submit, will be temporarily stored in the staging area of all submitted, the parent object submitted for the current branch HEAD.

View modify the specific content of each submission command:

git log -p  #通过上下键来查看所有提交修改的内容

tag an object , the object is both a tag type, is a reference in git, the reference in this section on the presentation.

 

1.3 Git references

That is the essence of pointer reference, Git branches and tags are submitted for reference (a pointer pointing to commit object), storage path located: .git / refs.

Label (tag) the object by object name, object type, name tag, label creator name components.

In git, the two types of labels, heavyweight and lightweight tag tag. Lightweight tag to commit the type of object. Heavyweight tag type for the object tag, will generate a tag object in the object library when creating the tag heavyweight, lightweight tag of just cited commit.

Tag branches (Branch) compared to all point to a commit, the label can be seen as a constant pointer, it can not be changed ; the branch is a pointer variable . On the use of branching and tagging, I will repeat that alone later.

Released three original articles · won praise 0 · Views 94

Guess you like

Origin blog.csdn.net/qq_33669963/article/details/104103236