View the history of previous Git commits by reviewing the commit log.
- [Instructor] In this movie, we're going to learn how to view the commits that have been made to a Git project using the commit log. The way that we use the Git log is very simple. You first make sure that you're inside your Git project, and from there I just type Git, space, log. And this will return to me a log of all the commits that have been made to this project with the newest entry at the top. Everything's being logged is from commit all the way down here to where it says initial commit. That's my message. Let's take a look at some of the other parts. This first number up here, we'll talk a bit more about, but it is an ID number, it's a unique ID for every commit. Every commit is given a unique ID so that we can identify and know which commits we're talking about. Next, you'll see that there's the author. This is information that was pulled from our configuration file. Remember the very first thing we did when we started the project, was we configured it to know who the author was and what the email address was. And that's where its getting that information. Then, we have the date. The date that the commit was actually made. Followed by the commit message. Which in this case is just a single line but if it were longer, we would be seeing more of the message below that. Now that's the simplest way that we can use Git log. If you type Git, help, log, you'll find out more about the log command and you'll see that there a lot of different options that you can use. I'm going to show you just a couple of the most useful ones right now. If I type Git log and I follow it with the -n option and then a number, then it will limit the number of commits that it shows me to that number. I only have one commit, but lets imagine that I had 50 commits that had been made. Git log -n5 would show me only the five most recent of those. Another useful one is to limit them by time, and we can use Git log with --since and then equals, and then a date let's say 2019-01-01. So, this will show me all commits that have happened since January 1st of 2019. Now that of course applies to my commit if I go in and I change it to 2020 which for me is in the future, then you see it doesn't show anything. Now, I can also change since to be until. Show me everything until that date. So that's everything going backwards. So I can limit it with since and until and you can use both of them of course as well. I can also limit it by the author. Git log --author and for the author I don't have to type the full name I can type any part of the name. So, I'm just going to type in Kevin and you'll see that it brings up that commit. It's actually looking for just the string inside there. And if there were several Kevin's who had committed to the same repository, then several of them would show up. And then on of the most useful ones is the ability to search for commit message. I'm just going to clear my screen so you can see it. Let's do Git log --grep. Grep is a commonly used term in computers and it says that we're going to globally search for regular expressions. That's what the G, R, E stands for. Globally searching for regular expressions. And so, we can put equals and we can put any kind of regular expression we want in there. I'm just going to put this simple string in it. That's my initial commit. It's finding in it, right there. So, it'll return any commit that has this string in it. So, if I'm looking for all bug fixes for example. Bug fix, right? All the big fixes would then show up. Or if I want to find everything that's related to a certain Git hub issue. I could have all of those show up. That's one of the reasons that it's very important to write good, descriptive commit messages is because then it enables us to go through and search our repository for code related to a certain topic or to a certain feature.
- Exploring the history of version control
- Installing Git on Mac, Windows, and Linux
- Initializing a repository
- Writing useful commit messages
- The Git three-tree architecture
- Tracking when files are added, edited, deleted, or moved
- Viewing change sets and comparing versions
- Undoing changes and retrieving previous versions
- Ignoring changes to select files