The Mijingo Blog

Latest news, updates, free tutorials, and more from Mijingo.

Understanding Git Log

by Ryan Irelan

Git logs allow you to review and read a history of everything that happens to a repository. The history is built using git-log, a simple tool with a ton of options for displaying commit history.

What’s in Log?

A Git log is a running record of commits. A full log has the following pieces:

  • A commit hash (SHA1 40 character checksum of the commits contents). Because it is generated based on the commit contents it is unique.
  • Commit Author metadata: The name and email address of the author of the commit.
  • Commit Date metadata: A date timestamp for the time of the commit
  • Commit title/message: The overview of the commit as written in the commit message.

A Typical Log

Git logs can be whatever you want them to be. Git-log offers dozens and dozens of options but let’s start with the simplest.

git log 

This outputs the most basic log:

commit 98aa8d722bdecc4e56156cfe1a793a4d16848eb8
Author: Ryan Irelan 
Date:   Sat Jan 10 23:26:40 2015 -0600
Adding in new homepage
Includes the assets needed for Foundation
commit dd8d6f587fa24327d5f5afd6fa8c3e604189c8d4
Author: Ryan Irelan 
Date:   Tue Jan 6 20:07:17 2015 -0600
added origination declaration at bottom of RSS feed

This is a snippet of the log, showing two commits. We have a commit SHA1 hash, the author, the date, and the commit message, explaining what happened in the commit. This layout is the default look of the log.

Git has something called Commit Limiting to make it easier to narrow down hundreds or thousands of commits to the ones you want to review.

Directory Restricted Log

The default log is great for grabbing a quick look at what just happened in the repository. But it takes up a lot space and you can only see a handful of commits at once.

When I’m developing a project, I sometimes only want to know what happened in a specific directory. Let’s say I’m working on some CSS or Sass and only want to know about changes in my Sass directory. I can get much more specific with git-log and restrict it only to a specific directory.

git log scss

This will only return commits that had changes in the scss directory.

Log by branch

We can use a similar syntax as directory restriction and build a log for just one branch. We only need to specify the branch we want to see.

git log develop

We can clean that up a little by removing any merge commits (which can bulk up the log if there are a lot of merges, like there would be a develop branch.

git log develop --no-merges

Learning More About Git-Log

To learn more about Git-log, like time-restricted logs, search logs, and more, check out our Intermediate Git course that will make you a Git power user.

Learn more about Git

New Lesson: Creating a Contact Form in Craft

by Ryan Irelan

There’s a new free lesson available over in Lessons area that covers how to build a contact form in Craft.

In the lesson, we add the form to our Crafty Brewery sample site so customers can contact us with questions about our brew products and recipes.

We’ve been building the Crafty Brewery site over the course of several videos in the Learning Craft video course. If you want to learn more about Craft, I encourage you to check out that series of videos.

During this lesson, here’s what we’ll learn:

  • How to install and configure the Craft first party Contact Form plugin.
  • How to code the Contact form template
  • How to add a honeypot CAPTCHA to the form.

Watch the Free Lesson

How to Create Git Aliases

by Ryan Irelan

An alias, otherwise known as a shortcut, allows to place a simple command in front of a longer or less memorable command.

For example, we could type:

git commit -m "some change"

Or we could type even less and do:

git c -m "some change"

We’re only saving a few letters but considering how many times you commit in a day or week, it’s a bit easier on your fingers. Less tapping of the keyboard and more working on the fun code.

To create a Git alias, we need to open up our .gitconfig file and edit it. Because we want to have these aliases available to us in every project, we are going to edit the .gitconfig file in our user directory.

If you don’t already have the file in your user directory, that’s okay. We can have Git handle that for us.

We’ll create an alias first using the git-config command, to which we pass the type of config file (in our case it’ll be global in our user home directory) and then define the alias.

git config --global alias.c commit

This will add the following line to our ~/.gitconfig file. Let’s take a look to see if it was saved.

git config --list

This lists out all of our config items and you should see the alias:

c = commit

listed as output.

Now we have access to that alias within Git. We can type:

git c -m "something"

and it will work just as if we typed out the full command.

Let’s open up the config file and take a look. We’ll open ours in Vim, but you can use any editor you want.

vim ~/.gitconfig

You should see something like this:

    c = commit

Let’s add another alias by hand without using the git-config command. It’s just a text file so we can edit it and type out our alias by hand.

Let’s add an alias to make it quicker to get the status of our working directory. Under the existing alias for commit, let’s add this:

st = status

We’ll save our .gitignore file and then try it out.

git st

And we should get some output from Git (assuming we’re inside a Git project) as if we ran the full command.

We can add another for git-log, too.

l = log

And how retrieving the basic log is two letters faster than before!

Okay, let’s do one more to quickly archive the entire repository.

Git provides a command called git-archive that allows us to export the entire repository as either a zip for tar archive file.

git archive --format=zip -o HEAD 

This command will output the current repository at HEAD to the a zip file named It will save the file right where you are in the repository.

This can come in handy if you have to quickly share your work with someone who is not in the Git repository or if you need to throw the files up on a server somewhere.

To alias this we add this to our .gitconfig file:

zip = git archive --format=zip -o HEAD

Now when we run:

git zip

in a valid Git project directory, git-archive will zip up the entire project and place it in the project root.

One Bit of Advice

You don’t have to have a fully decked out .gitconfig file right from the get-go. Add aliases to your config file as it makes sense and as you need them. They can be tough to remember if you add too many at once!

Ready to learn more about Git?

We have courses, articles, and tutorials on Git. Start learning immediately!

See the courses

ExpressionEngine Courses Price Reduced

by Ryan Irelan

Last week EllisLab released ExpressionEngine 3, the latest major update to the CMS. You can read more about this update on their blog.

The new version sports a brand new control panel interface, a revamped add-on development framework, and other changes.

However, the templating system is the same and how you structure and build your websites on ExpressionEngine should not fundamentally change.

My ExpressionEngine tutorials and courses are still useful because of the fundamentals they teach. However, some of them will be more challenging to follow along with because the Control Panel is different.

This doesn’t mean you can’t learn from them but it does mean it might be a little bit of extra work.

Because of that I’ve slashed the price on courses by up to 60%. For example, you can get the Learning ExpressionEngine course for only $20 (normally $49.99).

Quite the deal.

I’ll have more updates in the future about updates to the course (or, most likely, a brand new course) to cover ExpressionEngine 3.

If you want the course, please email me to let me know. If there’s high demand I’ll move it up on my list.

Filters in Twig and Craft

by Ryan Irelan

Filters in Twig and Craft allow you to alter the contents of a variable.

This could be a variable you set right in the template or one that is part of the data output provided by Craft (like when retrieving and looping through section entries).

Filters are applied right in the output tag, like this:

{{ variable | filter }}

and separated using the pipe character.

Here’s an example where we want to title case the string that is assigned to the variable.

{% set page_title = "an important news story" %}
{{ page_title | title }}

When outputting the contents of the page_title variable, we are running it through the title filter in Twig. This filter adjusts the string to title case, so every word starts with a capital letter.

It will output:

An Important News Story

Another very practical filter that you might use frequently is trim. This filter strips out whitespace at the beginning and end of a string.

{% set page_title = " an important news story " %}
{{ page_title | trim }}

That will remove the whitespace at the beginning and end of the string.

You can also trim specific characters by specifying them in parentheses.

{{ page_title | trim('.') }}

The previous example outputs:

an important news story

which is missing the title casing we did before.

Let’s add in both filters together. We do that by chaining together them with pipes.

{{ page_title | trim | title }}

That outputs:

An Important News Story

Craft-specific Filters

Pixel & Tonic created some special filters just to use in Craft. These filters won’t be listed in the Twig documentation, and, similarly, the Craft documentation won’t list all of the Twig filters. This is a situation where you’l need to refer to two different sets of documentation.

Here are a couple Craft filters that I find interesting:

  • markdown - processes the string passed to it using the Markdown library.
  • group - allows you to group array items together based on a common property that you define. The Craft docs have a great example of sorting the entries returned from a Craft section by the year of the entry.

Ready to learn more about the Craft CMS?

My Craft Starter Pack is 4 ½ hours of premium learning that will get you started building sites with Craft for yourself, your company, or your clients.

Get Immediate Access