![Git In-depth](https://static.frontendmasters.com/assets/courses/2018-02-20-git-in-depth/thumb.webp)
Check out a free preview of the full Git In-depth course
The "History and Diffs Solution" Lesson is part of the full, Git In-depth course featured in this preview video. Here's what you'd learn in this lesson:
Nina walks through the solution to History and Diffs Exercise.
Transcript from the "History and Diffs Solution" Lesson
[00:00:00]
>> Nina Zakharenko: Let's go through exercise five History & Diffs. First thing we're going to do is check out the exercise five branch.
>> Nina Zakharenko: The -f flag for check out will force the checkout, it'll overwrite any changes. I recommend not using this in your day-to-day work, you'll end up having a bad time.
[00:00:32]
But I'm just using it to check out this example exercise branch, because I had some uncommitted work.
>> Nina Zakharenko: Now that I am on exercise five,
>> Nina Zakharenko: We're gonna practice a good commit. I don't think I have to walk you guys through that, so I'm just going to comment at the file.
[00:01:02]
Here, say,
>> Nina Zakharenko: We're going to change our hello.txt.
>> Nina Zakharenko: And we're gonna make it say,
>> Nina Zakharenko: (greeting) (noun).
>> Nina Zakharenko: Great, now my hello.txt looks like that. And we're gonna rename it.
>> Nina Zakharenko: And then, we're going to commit that change. For brevity, I'm not going to show you what a good commit message looks like but hopefully, you all got to practice this during your exercise.
[00:02:10]
>> Nina Zakharenko: Cool., so now we have a good commit. Let's check out our commit with log.
>> Nina Zakharenko: So this should show us what commits were made since yesterday. Just this one.
>> Nina Zakharenko: Now, most importantly, let's try to track the hello.template file as its changed names, and we're going to do that with name status and the --follow flag.
[00:02:43]
--follow lets you follow a file as its changed names moved around, etc.
>> Nina Zakharenko: Now, we'll see here that this is where it was renamed, and some other commits where that foul was modified. In the initial commit, we'll see A. A means, that's when it was added.
>> Nina Zakharenko: Now, let's use git grep, git log grep.
[00:03:24]
>> Nina Zakharenko: And let's search for the term, i18n, and author is going to be me. And the since is two weeks ago, oops.
>> Nina Zakharenko: Great, that went and found that commit.
>> Nina Zakharenko: Without the log grep for example, it would have pulled up all the commits, since they were all made by me in the course of the past two weeks.
[00:04:02]
Let's use diff filter to find where the file was renamed.
>> Nina Zakharenko: And there we go.
>> Nina Zakharenko: We can also use diff filter to specify and find out when were the files modified, that's using M.
>> Nina Zakharenko: These are all the commits where that file was modified.
>> Nina Zakharenko: Now that we found our commit,
[00:04:52]
>> Nina Zakharenko: I want to check this commit out, using git show.
>> Nina Zakharenko: So I copy and paste that hash, and here it is. It shows all the changes.
>> Nina Zakharenko: Now, how do we find out, how do we sort of diff branches, how do we find out which branches were merged into master and which ones weren't?
[00:05:20]
We can do that with git branch --merged, which ones were merged into master. Those two, which ones were not merged into master? We can use no merged.
>> Nina Zakharenko: Great, that's the end of exercise five.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops