Published March 1, 2020 Updated March 1, 2020
Git Rebase Reword
Demonstrates using rebase to reword a previously created commit.
# Hello and welcome to the Alchemists Screencasts! # Today, we'll learn about Git Rebase Reword. # Let's start by looking at the Git log of our current project: gl # By the way, I'm using my `gl` alias to reduce typing. # (short for *git log*) # Here's the source code: cype gl cype _git_log_line_format # The `gl` alias allows for an information rich and pretty Git log. # Let's study the Git history one more time: gl # Notice we have three commits total. # All commits read well except for the middle commit. # The first commit makes sense because it added the calculator script. # The second commit is documentation related but very vague. # The last commit added the project license. # Let's see if we can learn more:
ghow # The commit has no body so we don't know *why* the commit was added. # We can see it added a `README.adoc` file, though. # Let's reword this commit since it's confusing to understand. # Luckily, Git Interactive Rebase can help in this regard: git rebase --interactive
# You might be wondering why I changed "p" to "r" and added "b". # The "b" is short for "break" because I wanted to halt the rebase before rewording. # By *breaking* here, I can explain the details before continuing the rebase. 😉 # The "r" is short for "reword" so we can reword the commit. # OK, with that explained, let's continue so we can reword the commit. 🎉 git rebase --continue
gl # Notice the middle commit has been reworded as desired now:
ghow # The above commit message is *much more* understandable now. # We now understand *what* the commit is (i.e. the subject). # We also know *why* the commit was made (i.e. the body). # The body (*why*) must always support the subject (*what*). # This information is critical for historical and debugging purposes. # Both your future self and your team will thank you! # Enjoy! # https://alchemists.io # ☿ 🜔 🜍 🜂 🜃 🜁 🜄