Animating the Git Branching Model: Part 1

I’ve been trying to learn Apple Motion 5.  In my day job, I draw a lot of architecture diagrams to communicate with clients and with my technical teams.  I find the use of the visual to be clarifying, therapeutic, and highly-effective.  Up until this point, I’ve focused on static diagrams that I can whip up using OmniGraffle. But the notion of motion has always enticed me.
This post does two things.  First, it brags about my first attempt at producing an animated gif using a combination of Apple Motion 5, and ffmpeg and gifsicle.  Second, it thematically advances a framework I had introduced in my last post which argued that to understand Git, you need to understand its underlying models. In that last post, I focused on the Places Model.  Today, I want to start illustrating the Branching Model.  

I am under no illusions that what I am providing is the best approach to understanding this model.  However, if even a few people find this animated gif useful, then it will have been worth it. (Personally, I wish I had something like this when I was first learning Git.)

Anticlimactically:

You will find at the bottom of this post the steps you can copy-and-paste to follow along with what is going on in this animation.  This is my first animation and I decided to keep it simple.  Initially I wanted to show all the trickery that occurred with all the forms of git reset (from soft to hard), to the graph-rewriting git rebase, to the confusions of a detached HEAD.  For now, I find this most basic explanation to be a necessary first step.  Those other animations will follow.


Here are some things that are worth noting about what’s going on in the animation:
  1. I am NOT showing what’s going on in the Places Model and the Content Model. You are not seeing how content is being added to the index from the working directory, or how content is being added as blobs.  All we are seeing is the temporal evolution of a DAG of commits.
  2. A git checkout is literally changing a pointer to a pointer, moving HEAD to point to a branch.
  3. A branch is nothing more than a pointer in a DAG of commits.
  4. The Branch Model uses commits as a proxy for the full DAG of the Content Model which includes graph objects of type commit, blob, tag, and tree, etc.  Each commit object is the starting point to a DAG that represents the state of the code from that point.  To repeat:  we are showing the DAG for the Branch Model, and not the full DAG of the Content Model.

Steps to Follow Along with Animation

   (copy and paste these into a command-line prompt on your favorite *nix)
  1. mkdir ordoTempliOrientis;  cd ordoTempliOrientis
  2. git init
  3. touch fileNum{1..5}.txt; git add fileNum*
  4. git commit -a -m "adding five empty files"
  5. echo "first line" >> fileNum1.txt;  git commit -a -m "adding a line… praise LBJ"
  6. echo "another line" >> fileNum1.txt;  git commit -a -m "adding a 2nd line"
  7. git branch fixXSSBug
  8. git checkout fixXSSBug
  9. echo "over here" >> fileNum2.txt; git commit -a -m "modifying different file -- 1st time"
  10. echo "adding a 2nd line in new branch" >> fileNum2.txt;  git commit -a -m "This is the 2nd commit on branch"
  11. echo "adding a 2nd line in new branch" >> fileNum2.txt; git commit -a -m "3rd commit on branch"
  12. git checkout master
  13. echo "When in disgrace" >> fileNum1.txt;  git commit -a -m "1st Sonnet Commit"
  14. echo "with FORTUNE and MENs eyes" >> fileNum1.txt;  git commit -a -m "Bill would be proud"


Now, if you want to verify that these steps worked, feel free to run ‘gitk --all‘ from the command line and you should see this:
More interesting and complicated Branching Model animations to follow. Feel free to steal.

No comments:

Post a Comment