preface

Git init () : git init () : git init () : git init () : git init () : git init ();

The git directory

  • Hooks: If you want to start a hook script, you can remove the suffix simple from the file name of the script. These hooks will be triggered at a specific time. For example, post-commit is executed after the whole commit process is complete, which can be used to send commit notifications, etc. There are also server-side hooks that can be executed before or after the push. For example, post-receive is executed after the push, which can be used to notify the packaging platform to start the packaging task. For more information about git hooks, see customizing Git – Git hooks.

  • Info: Saves git information

  • logs

    • Refs: temporary record, local branch record, remote branch record

    • HEAD: Records each change operation

  • Objects: Stores real data as Git objects

  • refs

    • Heads: Stores the latest COMMIT hashes of all local branches

    • Stash: Stores the hash value of stash

    • Tags: Store tags related

  • Config: indicates the configuration file

  • HEAD: the current branch does not hold the SHA1 value, like /refs/heads/master. This points to a file that contains the SHA1 value of the latest commit

  • Index: binary file, temporary storage area

Several objects in Git

  • The data object

    Data objects are used to store real file data and are created as follows:

    1. Calculate the content size and construct the header

    2. Construct the data object by adding the header to the front of the content

    3. Use the SHA1 algorithm to calculate the 160-bit hash code of the Git object, which is 40 bits in hexadecimal format

    4. Use Zlib’s Deflate algorithm to compress data objects

    5. Git /objectes/ to the first two bits of the hash code and the last 38 bits of the hash code

  • The tree object

    Save directory information, that is, version control information for the non-leaf nodes of the directory tree, needs to be created from the staging area.

  • Commit object

    Saves details of a submission, including when, who, and so on.

  • Tag object

    Similar to a Commit object, it contains a pointer to a Commit object that will never change.

Git commit process principle

  1. Add to staging: git add XXX

    • Creating a data object

    • Update index file

  2. Git commit -m “XXXX”

    • If a directory exists, the tree object is created

    • Creating a COMMIT object

  3. Save the objects created above as directories and files

Git commits to create data objects, tree objects, and commit objects, all of which are stored in the Objects directory.

Git data storage principles

Git is loose object format that is used by the default is every time a complete data, such as a large file 10 MB, submit is stored up for the first time, changed a few things behind and submit, then Git will hold two 10 MB of object data, it will look more waste, it is best to save the file only difference parts.

If there are too many loose objects, or push, or Git gc, Git will pack them into a pack file. This file will save the difference between the different versions of the file, reducing the storage footprint, and making the pack file binary. You need to run the git verify-pack command to check it.

Note that Pack keeps the latest version as a full object, while previous versions keep the difference information, because most of the time the latest version will be accessed.

Git Transport protocol

Git has four transport protocols, including local protocol, HTTP protocol, SSH protocol, Git protocol.

  • Local agreement

    The remote repository is stored on a hard disk. The hard disk can be a network disk mounted remotely. The address of the remote repository can be specified as a directory path or prefixed with file. However, a shared file system is cumbersome and slow to configure.

  • The HTTP protocol

    Git 1.6.6 uses HTTP/HTTPS protocol for transmission. There are two types of protocols: dumb protocol and smart protocol. Dumb protocol was used before Git 1.6.6, which introduced smart protocol.

    • Dumb agreement

      1. Get the info/refs file and determine the SHA1 value of the latest COMMIT for all branches

      2. Get the HEAD file, determine the current branch, and check out to the working directory

      3. Get the data for the first COMMIT object

      4. Go back and get all the object data

    • Smart protocols (mostly used)

      Whether uploading (such as push) or downloading (such as pull), the client starts a process, the server starts a process, and then negotiates the data to be transferred. The process port is HTTP or HTTPS.

    HTTP protocol has the following advantages: 1. It is easy to use, only need a remote address. 2. Easy authentication, directly enter the user name and password, as the first SSH configuration is not as troublesome.

  • SSH protocol

    When using SSH as the transport protocol, you need to configure SSH information so that you do not need to enter the user name and password each time.

  • The Git protocol

    Git protocol has no authorization mechanism, that is, it cannot control whether some people can push and others cannot push. Therefore, in most cases, Git protocol is only open for reading and forbids push.

Git Flow is a collaborative process

Stable branch

  • Develop a branch of development

  • Master: Publishing branch

Temporary branch

  • Feature: A feature branch that is used to temporarily develop new features, pulling from Develop and finally closing into Develop.

  • Release: a pre-release branch. After the Develop branch has finished developing requirements for the current release, it pulls the Release branch to fix bugs, configure release information, etc. At this point, the Develop branch continues to develop requirements for the next release. When the Release branch is finished modifying, you close it to Develop and Master. Note that the master is tagged with a name such as master_8.1.

  • Hotfix: The fix branch, used to fix emergent bugs online, pulls from master and eventually joins to Develop and Master. Note that the master is tagged with a name such as master-8.1.1.