Instructor: We are on the master branch of our project and if we do a log one line, we can see all of the commits we have.
Let's say we want to change an old commit message. The first thing I'll say is that we shouldn't want to change commit messages that are in the past on the origin. That means we've already pushed them and someone may have pulled them and we don't want to rewrite history that someone may have already pulled. Instead, we're going to make some new changes so we can play with that.
We're going to alert this is our first change, let's save that. If we do a status, then that has been changed. We're going to add app.js and commit our change one. We're going to duplicate that for change two, do the same thing, we're going to add app.js and commit change two. Do the same thing for a third change. We're going to add app.js and commit change three.
Now if we do a log one line, we have some commits here that are in front of the origin master. We can change this without worrying about rewriting history that someone else may have pulled.
What if I want to change this change one message to something else? For that, we're going to use rebase interactive. I'm going to do a git rebase and a - i for interactive. I want to go back three commits to change it.
I'm going to do head ~ 3, which is going to rebase all the way back to this commit, but leave that one alone and just give me access to these three. I hit enter here. This is the git rebase interactive interface. Just open the text editor here and the default is pick, which means leave this commits alone.
I also have all these options for my commits. In this case, I want to reword the commit. I'm going to hit I to enter insert mode and I'm going to change this pick to reword and hit escape:wq because this is VI and I need to save it. I've entered the commit message for change one.
You can see over here, we just have change one in our editor because we're on the change one commit. Over here, I could hit I again for insert and this is the change one new commit message. I can hit escape wq.
Now, if I do a git log one line, we can see first of all that we've successfully rebased. Our commit message here was changed and two and three were left alone and we're back on master, which has all three changes.