5.1. How Does Git Actually Work.md - shinokada/gitnotes GitHub Wiki

How Does Git Actually Work?

Git log

❯ git log -5 --oneline

Converting short has to long

❯ git rev-parse 319d378
e2c43d7ecaeaa797a5d896989495c5a40361a855

e2 in the e2c43d7ecaeaa797a5d896989495c5a40361a855 has is a directory and rest is the object identifier.

The Git object repository structure

❯ cd .git/objects
❯ ls
02   29   4a   69   81   9b   c0   e7   pack
...
❯ ls e2
c43d7ecaeaa797a5d896989495c5a40361a855

Viewing Git objects

❯ git cat-file -p e2c43d7                                  
tree 918a9a069571bbc640a1f433c62e90f58171f6cb
parent 49b1866559b6b8855c3aa01f4197c1eca90056a1
author Shinichi Okada <[email protected]> 1646720006 +0900
committer Shinichi Okada <[email protected]> 1646720006 +0900

The -p option here tells Git to figure out what type of object it’s dealing with and to provide appropriately formatted output.

The tree object

❯ git cat-file -p 918a9a069571bbc640a1f433c62e90f58171f6cb       
100644 blob 3ccf435f02ce260ecb9b59ecfbb042c0dff1ea26    .eslintrc.cjs
100644 blob d6ab2fb85e176ec73a1961294c9c22550f87b40b    .gitignore
100644 blob b6f27f135954640c8cc5bfd7b8c9922ca6eb2aad    .npmrc
100644 blob ff2677efde552bd0f6d7daecc4a6c4429d6f8151    .prettierrc
100644 blob 94a48f5ff868a92f77d5e2ca3b81ba6b20b9b719    README.md
100644 blob 7a8ae6bfb08e69478ad5d1eaa34b1256e493fb1d    package-lock.json
100644 blob 83738af88ab02a60e6c03d3accc7bb64b299f6c7    package.json
100644 blob 448008a2f18642889c06a50cd49c55f13c2b507e    playwright.config.js
100644 blob fe10e55a833c6a8da26f8c7ffa71246db8d48c44    postcss.config.cjs
040000 tree c7f86045f59d0ed55b93f317cf77c50b320c0a97    src
040000 tree 7682b0d50309ae43b647d5588c5c9f82ca6f3604    static
100644 blob 1398542878a0cca6fdaae7d997a11bb0c50d18d0    svelte.config.js
100644 blob 9b6e71b70a22320518e6503435e847eb64009f2c    tailwind.config.cjs
040000 tree 8f2df1a9febf89a9340e1beffc15f24269ab0934    tests
100644 blob 81ff9770cd8aef963618a2267208f8e0a6df209f    tsconfig.json

The blob object

❯ git cat-file -p 3ccf435f02ce260ecb9b59ecfbb042c0dff1ea26
module.exports = {
        root: true,
        parser: '@typescript-eslint/parser',
        extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
...        
⚠️ **GitHub.com Fallback** ⚠️