Get startedGet started for free

Viewing the version history

1. Viewing the version history

Welcome back! So, how can we see the version history of our files using Git? To do this, we need to understand how Git is storing data.

2. The commit structure

Git stores data through commits, which have three parts: the commit itself, the tree, and blobs. Let's examine each of these components. The commit contains metadata such as the author, log message, and commit time. The tree tracks the names and locations of files and directories when that commit happened. Think of it like a dictionary, with keys represented as unique identifiers, mapping to files or directories. For each file in the tree, there is a blob, which means binary large object. A blob may contain data of any kind. Blobs contain a compressed snapshot of the file's contents when the commit happened.

3. Visualizing the commit structure

Here, we visualize three commits to our repo to see these three components.

4. Visualizing the commit structure

In the first commit, we see a unique identifier ending in six-five. This identifier is known as a hash, which we will discuss later. Two files were modified in the tree - report.md and mental-health-survey.csv. The blob shows a snapshot of what the files contained at that time.

5. Visualizing the commit structure

In the second commit, three files are in the tree, but only two were modified - mental-health-survey.csv and a newly created summary statistics file. Therefore, the tree links report.md to the blob from the previous commit, as it wasn't modified in this commit.

6. Visualizing the commit structure

In the third and most recent commit, report-dot-md and mental-health-survey.csv are modified, with updated blobs created and linked to the tree. The summary statistics file wasn't changed, so the tree links to the blob in the second commit.

7. Git hash

Earlier, we mentioned a unique identifier called a hash. This is a 40-character string of numbers and letters like this. It is called a hash because Git produces it using a pseudo-random number generator called a hash function. Hashes enable Git to share data efficiently between repos. If two files are the same, their hashes will be the same. Therefore, Git can tell what information needs to be saved in which location by comparing hashes rather than entire files.

8. Git log

We can view commit information using the git log command, displaying all commits made to the repo in reverse chronological order, starting with the most recent commit. It will show the commit hash, author, date, and commit message. If the output doesn't fit in the terminal window, a colon will be at the end, indicating more commits. We can see more by pressing the space bar. To exit the log, we can press q and return to the terminal.

9. Let's practice!

Now let's use the commands we have learned to navigate the Git commit structure!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.