Git Graph Theory

For a more general version of this discussion, check out:

Think Like (a) Git: Graph Theory

Using this presentation

Details

Main talking points

Git repos are directed graphs of commits

The id of a git commit is a SHA-1 hash that includes its commit message and its parent(s)' id.

For your convenience

Humans don't like to talk about commits in terms of hashes. Fortunately, our robot overlords have given us a set of handles/pointers that make this process much easier.

HEAD

The HEAD pointer indicates the place in your commit history that you are currently viewing (and possibly editing). Whenever you hear someone talking about navigation or "moving around" in git, they're usually talking about moving this pointer.

Branch Pointers

Branch pointers define branches! For example: the master branch is defined by the sequence of commits between the location of the "master" branch pointer and the initial commit.

Tags

Tags are similar to branch pointers except that they don't move as branches grow. They're usually used to pick out a specific point in your project's history such as: "Release v1.0"

Commits are graph nodes

Pointers point to specific commits

git branch new-branch

Save Point Pattern

Remember: pointers are just pointers

Git commands are perfectly happy to use branch pointers, commit hashes, partial commit hashes, tags, relative pointers, etc to go where you need to in your commit history.

 

You don't need to make a "Save Point" branch, but it's a handy tool to remember where you were.

Try it!

# Navigate into your git repo

cd ~\your\repos\location

# Pick your favorite commit hash from the log 
# and run `git checkout` on the hash.

git log
git checkout <the hash that you picked>

# Now have a look around! 

ls
git log

Merge and Rebase

+

= ?

What does combining branches even mean?

Git Graph Theory

By Justin C

Git Graph Theory

  • 674