Version Control (Git)

PrettyMeng, code

Git's Data Model

Snapshots

Modeling history: relating snapshots

Data Model as Pseudocode

// a file is a bunch of bytes
type blob = array<byte>
// a directory contains named files or directories
type tree = map<string, tree | blob>
// a commit has parents, metadata and the top-level tree
type commit = struct {
parents: array<commit>
author: string
message: string
snapshot: tree
}

Objects and content-addressing

An Example Directory Structure
<root> (tree)
|
+- foo (tree)
| |
| + bar.txt (blob, contents = "hello world")
|
+- baz.txt (blob, contents = "git is wonderful")
$ git cat-file -p 698281bc680d1995c5f4caaf3359721a5a58d48d
100644 blob 4448adbf7ecd394f42ae135bbeed9676e894af85 baz.txt
040000 tree c68d233a33c5c06e0340e4c224f0afca87c8ce87 foo
$ git cat-file -p 4448adbf7ecd394f42ae135bbeed9676e894af85
git is wonderful
objects = map<string, object>
def store(object o):
id = sha1(o)
objects[id] = 0
def load(id):
return objects[id]

References

Repositories

Staging Area

Git Command: Manipulations of Objects or References

Git Basics

Write Good Commit Messages

Branching and Merging for Parallel Development

Remotes

Undo

Advanced Git

More about Git

CC BY-NC 4.0 © PrettyMeng.RSS