Page 27 - MSDN Magazine, June 2017
P. 27
Visual Studio 2017
MinGit API
Official Git Source
repo and each vertex represents a data element known as a commit object (see Figure 2). Vertices in a DAG are connected with a line called an edge; it’s customary for DAG edges to be drawn as arrows so they can express a parent/child relationship (the head points to the parent vertex; the tail points to the child vertex). The origin vertex represents the repo’s first commit; a terminal vertex has no child. DAG edges express the exact parent-child relationship between each of its vertices. Because Git commit objects (“commits”) are vertices, Git can leverage the DAG structure to model the parent-child
Figure 1 Communication Paths to and from the MinGit API and the Git for Windows Command-Line Interface
when you issue porcelain commands, they’re translated into plumb- ing commands before being processed by the CLI. The point here is to understand that Git experts often resort to—and some thrive on—issuing bare-metal Git plumbing commands to a CLI because doing so is the most direct, lowest-level way with which to man- age, query and update a Git repo. In contrast to low-level plumbing commands, higher-level porcelain commands and Git operations exposed by the Visual Studio IDE also can update the Git repo—yet it’s not always clear how, especially because porcelain commands often accept options that change what they do when they’re invoked. I’ve concluded that familiarity with Git plumbing commands is essential to wielding the power of Git and that’s why I strongly rec- ommend installing G4W alongside Visual Studio 2017. (Read details about Git plumbing and porcelain commands at git-scm.com/docs.)
Low-Level Git
relationship between every commit, giving Git its ability to generate a history of changes from any commit back to the repo’s initial commit. Furthermore, unlike linear graphs, a DAG supports branches (a parent with more than one child), as well as merges (a child with more than one parent). A Git branch is spawned when- ever a commit object produces a new child and a merge occurs when commit objects are combined to form a child.
I’ve explored the DAG and its associated terminology in great detail because such knowledge is a prerequisite to understanding advanced Git operations, which tend to work by manipulating ver- tices on the Git DAG. Furthermore, DAGs help to visualize the Git repo, and they’re widely leveraged in teaching materials, during presentations and by Git GUI tools.
Git Objects Overview So far I’ve mentioned only the Git commit object. However, Git actually stores four different object types in its
It’s natural for a Visual Studio developer to try to leverage existing
knowledge of a VCS, such as Team Foundation Server (TFS), when
transitioning to Git. Indeed, there’s an overlap in the terms and concepts
used to describe operations in both systems—such as checking out/ (repo’s tail
checking in code, merging, branching and so on. However, the assump- original (points B1 tion that a similar vocabulary implies similar underlying operations commit) to child)
C1
Git VCS is fundamentally different in how it stores and tracks files
and in the way it implements familiar version-control features. In
short, when transitioning to Git, it’s probably best to just forget
everything you know about centralized VCSes and start afresh. head
When you’re working on a Visual Studio project that’s under (points to Git source control, the typical edit/stage/commit workflow works parent) something like this: You add, edit and delete (collectively hereafter,
“change”) files in your project as needed. When ready, you stage some
or all of those changes before committing them to the repo. Once
committed, those changes become part of the repo’s complete and
transparent history. Now, let’s see how Git manages all that internally.
The Directed Acyclic Graph Behind the scenes, each commit ends up as a vertex (node) on a Git-managed directed acyclic graph (“DAG,” in graph-theory parlance). The DAG represents the Git msdnmagazine.com
PowerShell/ Command Prompt
G4W Command- Line Interface
Git Plumbing Commands
origin vertex
Git Porcelain Commands
Git Repo
Common MinGit and G4W Configuration Files
vertex
(commit object)
edge
(connects two commit objects)
is downright wrong and dangerous. That’s because the decentralized branch occurred
B2
merge occurred
A5 C2
terminal vertex
(last commit object on branch)
B3
A6
A1 A2 A3 A4
branch occurred
Figure 2 A Directed Acyclic Graph Showing Vertex, Edge, Head, Tail, Origin Vertex and Terminal Vertices; Three Branches (A, B and C); Two Branch Events (at A4); and One Merge Event (B3 and A5 Are Merged at A6)
June 2017 23
terminal vertex (last commit object on branch)
Command Feedback