Reword a Commit with Git Rebase

Jamund Ferguson
InstructorJamund Ferguson
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

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

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.