Git popular science is not mentioned here, baidu search has a lot of

Git: add and commit git: add and commit

Git database files are stored in a. Git /objects directory. The following commands are used to query git database files: Git cat – file – t < > key values and git cat – file – p < key value > (-t for viewing key values corresponding to the data type, – p for the key content of the corresponding data)

Finally, there is the git ls-files –stage command (see staging file contents)


First find a directory to initialize a git repository (select F:// git here)



After the command is executed, a. GIT folder is added to the F://GIT directory



Info and pack hold git data files that have been trimmed after executing git gc.



add

The add command puts file data into the staging area (concept baidu), which is actually a file (.git/index). Nothing has been done in the Git repository yet, so there is no file



Get into the business

  1. F://GIT create a demo.txt file in the F://GIT directory with the contents of the add (optional), then do an add operation (omitted).
  2. Git ls-files –stage git ls-files –stage
  3. This is the contents of the staging area, d28d40b18823a27071d0e9ce89c149adb3f9c4ee is a hash values (keys), pointing. Git/objects of a particular file; The final demo. TXT file is the path of the add object file
  4. A look. Git/change under the objects, a d2 folder (in fact, the above hash value of the first two characters), d2 folder a file, file name is the character after the hash value (8 d40b18823a27071d0e9ce89c149adb3f9c4ee)
  5. Git cat-file -t < key value > to see the file type (key value use abbreviation) and discover the bloB storage object mentioned above
  6. Git cat-file -p < key value > git cat-file -p < key value

Add generates a BLOB storage object. Next, look at COMMIT

PS: index file content rule: The same file is overwritten (always save the latest), different files are added, delete the current add, only the corresponding file information will be deleted, the previous information still exists, you can try by yourself

commit

  1. Commit on top of the previous add (message version1)
  2. See.git/ Objects changes, two more files (tree and commit)
  3. Look at the contents of the first folder (as with blob storage objects, the folder name and file name combine to form the corresponding key value of the storage object)
  4. The bloB is stored in a tree and contains the key values and file path of the bloB (demo.txt).
  5. Finally, look at the type and content of another file, and see the result. This file corresponds to the commit store object, the content records the key value of the corresponding tree object, the commit information and the time, and the corresponding COMMIT Message (version1) should also have a parent message (the value of the last commit key), which we didn’t see because we only committed once

At this point, git continues to correspond to the version of the context out

The diagram



Last but not least, git indexes. Without git indexes, you would have to read a lot of files every time and look up…. Slow death of personal

The.git directory contains an index to the current branch of the search file (.git\logs\HEAD) containing the following contents



The basic summary

At the heart of Git is its object database, the most important of which are commit, Tree, and BLOb objects

Commit: Records additional information, including the hash key value of the tree object, hash key value of the last commit, version author, version sequence, version description, and commit time

Tree: records the file name and directory structure of the corresponding version

Blob: A record of the contents of a file

Git finds the corresponding file by key value, which makes it easier to locate the commit of a certain version. Git branches, tags and other functions are implemented based on it.