Page 28 - MSDN Magazine, June 2017
P. 28
Figure 3 A New Visual Studio Project with Its Git-Repo History Report
The History - master window displays several columns of information. At the left (Marker 4) are two vertices on the DAG; each graphically represents a commit on the Git DAG. The ID, Author, Date and Message columns (Marker 5) show details about the commit. The HEAD for the master branch is indicated by a dark red pointer (Marker 6)—I’ll fully explain the meaning of this toward the end of this article. This HEAD marks the location of the next edge arrow’s head after a commit adds a new vertex to the DAG.
The report shows that Visual Studio issued two commits, each with its own Commit ID (Marker 7). The first (earliest) is uniquely identified with ID a759f283; the second with bfeb0957. These values are truncated from the full 40-character hexadecimal Secure Hash Algorithm 1 (SHA-1).
repo: commit, tree, blob and tag. To investigate each of these, launch Visual Studio (I’m using Visual Studio 2017, but earlier versions that include Git support will work similarly) and create a new console application using File | New Project. Give your project a name, check the Create new Git repository checkbox and click OK. (If you haven’t configured Git within Visual Studio before, you’ll see a Git User Information dialog box appear. If you do, specify your name and e-mail address—this information is written to the Git repo for each of your commits—and check the “Set in global .gitconfig” checkbox if you want to use this information for every Git repo on your machine.)
When done, open a Solution Explorer window (see Figure 3, Mark- er 1). You’ll see light-blue lock icons next to files that are checked- in—even though I haven’t yet issued a commit! (This is an example showing that Visual Studio sometimes carries out actions against your repo that you might not anticipate.) To see exactly what Visual Studio did, look at the history of changes for the current branch.
Git names the default branch master and makes it the current branch. Visual Studio displays the current branch name at the right edge of its status bar (Marker 2). The current branch identifies the commit object on the DAG that will be the parent of the next com- mit (more on branches later). To view the commit history for the current branch, click the master label (Marker 2) then select View History (Marker 3) from the menu.
The SHA-1 is a cryptographic hash function engineered to detect corruption by taking a message, such as the commit data, and creating a message digest—the full SHA-1 hash value—such as the commit ID. In short, the SHA-1 hash acts not only like a checksum, but also like a GUID because it provides roughly 1.46 x 1048 unique combinations. Like many other Git tools, Visual Studio expresses only the first eight characters of the full value because these pro- vide 4.3 billion unique values, enough to avoid collisions in your daily work. If you want to see the full SHA-1 value, hover the mouse over a line in the History report (Marker 8).
While the View History report’s message column indicates the stated purpose of each commit (provided by the committer during a commit), it is, after all, just a comment. To examine a commit’s actual changes, right-click a row in the list and select View Commit Details (see Figure 4).
The first commit (Marker 1) shows two changes: .gitignore and .gitattributes (I discussed these files in my previous article). The [add] next to each indicates files added to the repo. The second commit (Marker 2) shows five files added and also displays its parent-commit object’s ID as a clickable link. To copy the entire SHA-1 value to the clipboard, simply click the Actions menu and select Copy Commit ID.
File-System Implementation of a Git Repo To see how Git stores these files in the repo, right-click the solution (not the proj- ect) in Solution Explorer and select Open Folder in File Explorer. In the solution’s root you’ll see a hidden folder called .git (if you don’t see .git, click Hidden items in the File Explorer View menu). The .git folder is the Git repo for your project. Its objects folder defines the DAG: All DAG vertices and all parent-child relationships between each vertex are encoded by files that represent every com- mit in the repo starting with the origin vertex (refer back to Figure 2). The .git folder’s HEAD file and refs folder
define branches. Let’s look at these .git items in detail.
Exploring Git Objects
The .git\\\\objects folder stores all Git object types: commit (for commits), tree (for folders), blob (for binary files) and tag (a friendly commit-object alias).
DevOps
Figure 4 Commit Details for the Repo’s First Two Commits 24 msdn magazine