Commit History

After creating the initial commit, it's time to create the next one! Creating commits with meaningful, concise messages is key to build a readable Commit History. You can imagine it as a timeline of all changes ever done in a version controlled folder aka repository.

Goodbye GIT GUI

Now I haven't used GIT GUI for this previously, then I did and then I realized that it's not beautiful. For me personally - I love beautiful things, so let me introduce a new tool to your toolkit. (I will show you the UI at the end of this post, you'll understand.)

Sourcetree

Sourcetree is a wonderful tool built by the fantastic people at Atlassian. It is available both for Windows and Mac users. They have a bunch of great tools, but let's focus on Sourcetree now.

So download Sourcetree, and install it, like you usually install stuff, but let's skip the registration part for now. You can always register an account later. Same with the SSH key creation.

Sourcetree

After opening it, you should see something like in the screenshot above.

Next up - click "Add" and find the folder you created previously (in the previous post).

Sourcetree2

If you see the text "Nothing to commit", you've made it! Please notice in the upper left corner, where it says "Workspace" - you are currently on the "File Status" page. Since you already created a commit for the changes in the previous post, there's nothing new to commit.

Commit History

Now go to "History", which is right under "File Status".

There's your commit!

You can see all of the various details about it in the lower middle section:

  • Commit - the commit ID
  • Author - the author info of who created it
  • Date - date of creation
  • Committer - the one who finalized the commit

and the commit message you provided previously.

Cool!

Let's add another commit to unlock the powers of time travel.

To do so, open the text file and change the text to anything else you want. Literally anything, just so there is a change to commit.

Once you save the text file, you will notice that the "History" page in Sourcetree has changed to reflect the new status of the repository - it has uncommitted changes.

Go back to the "File Status" page. You will see it has changed aswell.

Repeat

So just as creating the initial commit, you have to stage the changed files that you want to include in the commit.

Sourcetree3

Once you click on the file in the Unstaged files window, you will see the exact changes in what is called a DIFF (for difference) view on the right side. As the name suggests, it shows you what's changed with the old content in red and the new content in green. Simple, elegant, practical.

So press either "Stage All" or "Stage Selected" if you have selected the file.

Then, same as before - you have to provide a message for the commit (to be seen in the Commit History) and press the "Commit" button, which is in the bottom right corner.

If after that you see the screen refresh and show "Nothing to commit", you've succesfuly established a small (very tiny) Commit History!

Time Travel

Time to Time Travel.

If you open the text file, you will see the latest version. If you open the "History" tab in Sourcetree, you will see that indeed we are currently "on" the latest version of the repository.

Now you're probably wondering how we got here. Let's rewind.

Right-click the initial commit (the first one you made) and choose "Checkout..." and don't worry about the message of having your HEAD detached. I can assure you, you will come out on the other end with your head intact.

I will explain what "HEAD" is later in the post, for now just imagine it as the needle of a vinyl record player, which you now have chosen to place elsewhere on the vinyl and Sourcetree is warning you that you might not understand the context of the whole song.

Just press "OK".

If you now open the text file, you will now see the text that was there previously, before you made any changes.

Time Travel Abilities - Unlocked!

You can get back to the latest version the same way, by right-clicking and checking out the latest commit.

Summary

Git is a very advanced version control system, you probably noticed we didn't go over each button and term that we saw. Most of the time, you won't need to use most of the functionality. The functionality you will most likely use deserves that each principle is described in detail, with examples, so more on that in the next posts!

Sourcetree isn't the only tool, of course. If you're curious, you can open GIT GUI again, then press "Repository" in the top navigation and select "Visualize master's History" and you can see the way GIT GUI shows the commit history.

Subjectively, I like Sourcetree way better (be sure to check out the other epicness that Atlassion offers).