Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Reword a Commit with Git Rebase

    Jamund FergusonJamund Ferguson
    gitgit

    This lesson demonstrates how to use the git rebase command to reword a commit message deep in your git history.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 00:00 Here I am in a Git repo with only one commit, called first commit.

    00:03 The right-hand side of the screen is showing the continuous output of the Git log command. Type "touch one, two, three, four" to create four new files. Let's add each of this to the Git repository one at a time -- git add one, git commit -m one, git add two, git commit -m two.

    00:25 You'll see as we add these commits, they appear on the right-hand side of the screen. Let's add the third one, but this time, when we type git commit -m, we're going to misspell it on purpose. I'm going to add a bunch of Es in there. Let's carry on and add four, git commit -m four.

    00:43 Now on the right-hand side, we can see all four additional commits -- one, two, three, and four. We're going to use the interactive rebase command to adjust the misspelled commit message.

    00:54 To do that, we'll type "git rebase -i," followed by a commit hash that was made before the one we want to change. In this case, we use the commit hash for first commit, 5c34605.

    01:08 That's going to pull up a screen like this, which lists all of the commits made after the one that we chose -- one, two, three, and four. It also provides a list of commands we can choose from to apply to each of those commits, including pick, reword, edit, and squash.

    01:23 Each of these commands comes with a shorthand, like p, or r, or e for edit, that we can use to apply to one or more of these commits. In our case, we want to reword the commit that says "three" there. Let's go to the line and replace "pick" with "r." Then we'll save this file.

    01:43 That will bring us to a screen where we can edit the commit message. Let's change this "three" down to "three" spelled correctly, and save the file. Now you can see in our log that we have the commits four, three, two, one, and each of them are spelled correctly.

    Discuss

    Discuss