How to use the diff command to review modifications

Description

Collection: Change Management and Version ControlChapter: Staging, Committing and Undoing in Git

Transcript

Let's go ahead and make another modification and let's take a look at how to review those modifications using a command called diff. So I'm going to jump back to the resource pack directory and I'm going to open up the second step file. It's just marked with 02, and I'm going to copy this and paste it over the input dot module file.

I'm also going to make a couple additional modifications. This step adds some new code. But let's go ahead and remove some codes.

So I'm going to take this line and delete it, and then let's go ahead and modify this text just a little bit. Okay. So I've added that as well.

Now, I'm going to save it and jump back to the command line. I'm going to clear the back scroll with the Command-K and I'm just going to do git diff. now, when I do that, it opens up vim, the text editor, and so we can go up or down using the arrow keys.

And let's go ahead and take a look at the output here. The things that stand out with color are actually the most important to us right now. The red is examples of lines that have been removed and the green are lines that have been added.

Now, notice that this is a modified line but it shows up as a removed line and an added line, and that's how the version control system works. Instead of tracking modifications within a line, it only tracks modifications to specific lines. So regardless of the number of changes that we make to this line, we could even add a space or indent it.

That would constitute a modification and so the original line would be removed and the new line would be added. We also see our removed line here which is the one that we deleted. And if we continue to scroll down, you'll see that we have some code added as well.

If you can't depend on the colors for some reason, there's also a negative sign next to lines that have been removed and a plus sign next to the lines that have been added. I'm going to scroll back up to the top here. So let's go ahead and look at this line by line.

This initial line here, it's just rolling over on the two lines because it's particularly long, is a header in git format and you can tell it's in git format because it begins with diff dash dash git. And this is simply the nam ...

In this series we uncover how to use powerful tools to speed up and stabilize the Drupal development process. We begin with a thorough walk-through of Git, the version control system. After we cover how to patch modules and upgrade Drupal from one minor version to another, we demonstrate how to use the Features module to version control components of Drupal that aren't typically available to version control. Finally, we wrap up with how to integrate Drush - a powerful command line tool for Drupal - into your workflow to speed up the process of doing everything we discussed earlier in the series.

Some of the key points we'll be covering include:

How to use the command line

How to work with the Features module to capture important database changes and make deployment easier.

How to use Git for version control

Best practices for working on a Drupal team

Who this collection is for

This video collection is mainly for developers who want to improve their deployment strategies and learn how to work on a shared Drupal code base with other developers. However, even if you are not a developer, our coverage of using Features and version control is extremely valuable for deploying Drupal sites and sharing reusable components between projects.

Prerequisites

Even if you are not a developer, you will be able to follow with most of this collection. When we talk about code we do not go into detail about the basic components of the code, so you may want to brush up on some coding basics in the "PHP Programming Basics" collection.

It looks like there might be an issue playing videos in this browser. We're working on better cross-brower experience, but in the meantime please try the latest Chrome or Firefox browsers. Or, you may be able to watch the video directly without progress tracking or transcript: