How to undo modifications to staged and unstaged files

Description

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

Transcript

So let's take a quick review of where we are by using git status. So what we're going to do now is begin rolling back our changes. The first change that we've made is unstaged.

It's a modified version of our input dot module file. And again, if we want some hints about what to do next, we can look here under these "Changes not staged for commit" section. So it has two suggestions.

First is use git add to update what will be committed. So if we want to take the changes that we've made and actually commit it, we need to stage it first and this will stage it by using git add or we can use git checkout and then the name of the file to discard changes in working directory. So this will roll back any changes that we've made to this particular file since our last commit.

Let's go ahead and do that. I'm going to go ahead and type git checkout dash dash and then the name of the file which I'll go ahead and copy since it's rather long. And then I'm going to hit enter.

Now, if I do git status again, what we'll see is that there's nothing to commit, working directory clean. So all of our modifications have been removed. I went ahead and cleared the back scroll with Command-K.

So in these next steps, we're going to keep rolling back changes and it's important to make the distinction between staged changes and unstaged changes. You're going to roll them back differently depending on what they are. So let's go ahead and stage some changes and then roll them back to unstaged and then roll them back to nonexistent.

And then we'll go back and revert an actual commit that we made before. Okay. Let's start by modifying the input dot module file.

I'm going to jump back to my editor and I'm going to copy all of the code that's in the second step and I'm going to paste it over input dot module. We've done this before. I'm going to save it and then I'm going to open up another file inside of this directory.

So we have a couple of files that have been modified. I'll open up input dot info and I'm going to remove all the text inside of it and save it. Just to show one more example of a change, I'm going to duplicate this file so there are two of them now.

It doesn't really matter what file you duplicate at this point. I'm going to go back to the command line and let's check out our status, git status. So you see we have changes not staged, two modifications here, and then we have one untracked file.

Let's go ahead and stage all of these. In order to add these, let's go ahead and jump into the directory. I'm going to go cd sites/all/modules/input.

And now that we're in there, we can just go ahead and do git add and then we'll select everything. Now, if we do git status, you see that we've added the new file and our two m ...

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: