Skip to content

Latest commit

 

History

History
115 lines (72 loc) · 3.42 KB

README.md

File metadata and controls

115 lines (72 loc) · 3.42 KB

Git Internals and SHA

Some Git Terms

  • Untracked files: New files that Git has not tracked.
  • Working area: Modified files/changes that are un-committed.
  • Staging area: Modified files/changes that are marked to go into the next commit.
  • Local repo: Local copy of the repository
  • Remote repo: Hosted repository on GitHub, GitLab, etc.

Basic Git Workflow

Git Workflow

Image source: https://backlog.com/git-tutorial/git-workflow/

Git Basics

Here is a cool webapp to visualizing Git stuffs: http://git-school.github.io/visualizing-git/

A very good guide to Git basics

Pro Git - Chapter 2

Command Reference

Pro Git - A3.2 Appendix C

How does Git work?

Inside Git, everything is an object.

Git objects

Everything in Git is represented in a few basic objects stored in the file system in the .git directory.

Blob

  • Data (code, pictures, etc.)

Tree

  • Pointers to files, content and other trees

Git Tree

Image source: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects

Commit

  • Author
  • Message
  • Pointer to a tree
  • Pointer to parent

Git Commit

Image source: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects

Ref (aka tag, branch, etc.)

  • Pointer to a commit

Git References

Image source: https://git-scm.com/book/en/v2/Git-Internals-Git-References

Read more

Git and Graphs

A Git repository is essentially a giant directed acyclic graph (DAG).

SHA1

Every object is stored on disk and has a SHA-1 hash as the filename.

But isn't SHA1 insecure?

Yes, but that does not matter in this context. Git uses SHA1 to keep track of data and check integrity. It is still a good hashing algorithm with a very-very low collision rate.

Content is King

Git is very smart. It does not keep track of files, it keeps track of the content. If you create 1000000000000 files with the same content, it will only create 1 blob. Also works if you create 2 files with the same content. 😉

Learn more about Git