Skip to content

Instantly share code, notes, and snippets.

@prokopsimek
Created August 20, 2019 10:42
Show Gist options
  • Save prokopsimek/074698feb2c53a13e40b8ce62800ded2 to your computer and use it in GitHub Desktop.
Save prokopsimek/074698feb2c53a13e40b8ce62800ded2 to your computer and use it in GitHub Desktop.
Understanding Git (by Zvonimir Spajic)

Understanding Git

  • Distributed version-control system for tracking changes in source code during software development.
  • Initinal release: 7 April 2005; 14 years ago
  • Original Author: Linus Torvalds, Finnish-American

Chapter 1: Data Model

src.: https://hackernoon.com/https-medium-com-zspajich-understanding-git-data-model-95eb16cc99f5

git init

# show .git
# show .git/objects

touch README.md
echo "Hello world" > README.md

touch index.js
echo "const a = 1;" > index.js

git add README.md index.js 
# Created pointer (TREE object) for 2 files (TREE objects can be nested)

git commit -m "Initial commit"
# Created COMMIT object that has pointer to it's tree object
  • Git generates a 40-character checksum (SHA-1) hash for every object and the first two characters of that checksum are used as directory name and the other 38 as file (object) name.
  • BLOB (Binary Large OBject) - collection of binary data stored as a single entity in a database management system.
# Show that the checksum is pointer to commit
git log

# Show the pointer to TREE object
git cat-file commit [COMMIT CHECKSUM]

# Show the pointers to files
git ls-tree [TREE CHECKSUM]

# Show the content of a file
git cat-file blob [FILE CHECKSUM]

Chapter 2: Branching

src.: https://hackernoon.com/understanding-git-branching-2662f5882f9

# Current branch
git branch 

# Show .git/refs

# Show that it contains last commit checksum
git log
cat .git/refs/heads/master

# Show .git/refs contains "feature"
git checkout -b feature

# Pointer to current ref
cat .git/HEAD

# Show that I'm not a liar
git checkout master
cat .git/HEAD

Chapter 2: Index

src.: https://hackernoon.com/understanding-git-index-4821a0765cf

# Explain .git/HEAD vs. .git/refs vs. .git/index (BLOB)

# and now!
git status
# You can see your diff

Bonus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment