Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Git: Architecture and object model

Understanding Git: Architecture and object model

Git can be somewhat difficult to grasp for the beginner. Let's unwrap how it works

Pierre GOUDJO

December 30, 2021
Tweet

More Decks by Pierre GOUDJO

Other Decks in Technology

Transcript

  1. Jesse Du ff i eld — Creator of LazyGit You've

    heard it before, git is powerful, but what good is that power when everything is so damn hard to do? … YOU HAVE GOT TO BE KIDDING ME!
  2. blob blob blob Git stores fi le hierarchies in trees

    tree . tree lib index.js README core.js
  3. “Index 1.0” “README 1.0” “Core 1.0” Git is a content-addressable

    fi lesystem tree . tree lib index.js README core.js
  4. “Index 1.0” “README 1.0” “Core 1.0” Git is a content-addressable

    fi lesystem tree . tree lib index.js README core.js 3c4e9c fa49b0 d8329f 1f7a7a 83baae
  5. “Index 2.0” “README 1.0” “Core 1.0” Git is a content-addressable

    fi lesystem tree . tree lib index.js README core.js fa49b0 d8329f 7d235a 83baae
  6. “Index 2.0” “README 1.0” “Core 1.0” Git is a content-addressable

    fi lesystem tree . tree lib index.js README core.js c45f23 fa49b0 d8329f 7d235a 83baae
  7. “Index 2.0” “README 1.0” “Core 1.0” Git is a content-addressable

    fi lesystem tree . tree lib index.js README core.js “Display 1.0” display.js fa49b0 7d235a 83baae
  8. “Index 2.0” “README 1.0” “Core 1.0” Git is a content-addressable

    fi lesystem tree . tree lib index.js README core.js “Display 1.0” display.js 4578fd fa49b0 a234f2 7d235a 83baae 4a8d75
  9. “Index 2.0” “README 1.0” “Core 2.0” tree . tree lib

    index.js README core.js “Display 1.0” display.js fa49b0 7d235a 4a8d75
  10. “Index 2.0” “README 1.0” “Core 2.0” tree . tree lib

    index.js README core.js “Display 1.0” display.js 78d321 fa49b0 ab5423 7d235a 55f321 4a8d75
  11. “Index 2.0” “README 1.0” “Core 2.0” With tree and objects,

    Git can represent snapshots of tracked directories at any given time tree . tree lib index.js README core.js “Display 1.0” display.js 78d321 fa49b0 ab5423 7d235a 55f321 4a8d75
  12. tree 78d321 tree a234f2 lib “Index 2.0” 7d235a “README 1.0”

    fa49b0 “Content 2.1” 54fd32 index.js README
  13. The commit add context to a snapshot tree 78d321 tree

    a234f2 lib “Index 2.0” 7d235a “README 1.0” fa49b0 commit 1 45fad1 Pierre 12/10/2021 “Content 2.1” 54fd32 index.js README
  14. commit 4 commit 3 commit 2 commit 1 The history

    can be reconstructed by following the ancestor tree
  15. Commits encode link to a snapshot and some metadata like

    the author, the reason of the change, the date…
  16. Without references, you would still have to remember the commit

    SHA-1 commit 1 a234f2 commit 2 7d235a refs/heads/master
  17. With references, we can also mimic tags commit 1 a234f2

    commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/tags/v1.0
  18. With references, we can also represent git objects retrieved from

    another repository commit 1 a234f2 commit 2 7d235a commit 3 8c535a refs/remotes/origin/ main refs/heads/main
  19. When git fetch origin, you retrieve new objects from another

    repository and update the reference of the remote reference commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1
  20. When git fetch origin, you retrieve new objects from another

    repository and update the reference of the remote reference commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/remotes/origin/ main refs/heads/main
  21. HEAD can be on a commit directly commit 1 a234f2

    commit 2 7d235a refs/heads/master HEAD commit 3 7d235a
  22. When a commit is created HEAD move to the new

    commit commit 1 a234f2 commit 2 7d235a refs/heads/master HEAD commit 3 7d235a commit 4 7d235a
  23. The ref is also modi fi ed when they are

    refs/head/refs/* commit 1 a234f2 commit 2 7d235a refs/heads/master HEAD commit 3 65df34
  24. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 HEAD git checkout main
  25. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git checkout origin/main
  26. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git checkout origin/main
  27. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 HEAD git checkout origin/main
  28. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git checkout origin/main commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/heads/main commit 5 4512fa
  29. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git checkout origin/main commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/heads/main commit 5 4512fa
  30. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git checkout origin/main commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/heads/main commit 5 4512fa HEAD
  31. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git fetch origin commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/heads/main commit 5 4512fa commit 5 4512fa
  32. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git fetch origin commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/heads/main commit 5 4512fa commit 5 4512fa
  33. commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit

    4 4512fa refs/remotes/origin/ main refs/heads/main refs/remotes/origin/ feature1 git fetch origin commit 1 a234f2 commit 2 7d235a commit 3 8c535a commit 4 4512fa refs/heads/main commit 5 4512fa commit 5 4512fa HEAD