Updating a Bad commit message (Git rebase)

(git rebase -i HEAD~3). The number is the end number of commits you want to review and the -i means you want it to be an interactive session. :) Now let's get moving.

Now that we are in a "rebase session", we will be using "vim" commands, if you're not familiar with vim commands, you can check out a cheat sheet of them here. Your terminal screen should look something like this:

Rebase Session

Once you're in the open session, we will want to hit i for insert with vim, then we will direct to the correct place with our arrow keys, change the first word in the line next to your commit. To rename commit, we will change it to reword, then after that hit esc then we will type :wq and hit enter since it's vim, this will save and exit.

Your will still be in your rebase session and should see the commit file open. it should look like this:

Let's do an example commit message change, here i'm going to change "Fix for key name" to "Fix for key value". I would start by hitting i for insert, then use arrow keys to change my message, then I would hit esc and then type :wq to save and quit and hit enter to execute. Now my commit has the new message saved. If you're renaming (rewording) multiple commits, the next one might appear. but if now, you should see a success message and exited out of the rebase session.

Success of rebase

Now you're ready to push your update to your remote git repository. If you try and see the message below, follow the instructions there, otherwise you're good to go.

NOTE: If you see see a remote counterpart error, follow instructions below.

Run git pull to resolve this, then you can push, it will pull all branches. Or if you want to just go ahead and push over your work, cause you know your update is the most recent, you can add a '--force' option.

Remember, this applies to managing git based on commit's vs branch methodology. Branch Methodology is more common and what you will find at most tech companies. You can read more about git methodologies here.

Thanks, hopefully this helped you and let me know if you have any feedback or questions.

Eric Cavazos

Eric Cavazos


I love to build software, workout, and snowboard...

View Comments