Git Rebase Fixup
Demonstrates how to use rebase to fix up a previously created commit.
# Hello and welcome to the Alchemists Screencasts! # Today, we'll learn about Git Rebase Fixup. # For context, work has begun on a Ruby script that adds two numbers: ruby calc.rb 1 2 # There's a problem, though. # Our team has requested we print mathematical calculations instead of sentences. # No problem, let's fix the original implementation: vi calc.rb
ruby calc.rb 1 2 # Much better, let's commit these changes: git commit --all --message "Fixed implementation" # The `--all` option was used to pick up all changes (in this case a single file). # The `--message` option was used to explain *what* was committed. # (I'll to talk more about `--message` in a moment) # To continue, let's study the Git log: gl # 💡 To learn more about the `gl` alias, see the *Git Log Pretty* screencast. # Notice the third commit is where we added the original implementation. # For clarity, here's the subject used: "Added calculator implementation". # Our last commit is actually a *fixup* commit to the above commit. # This is why I used `--message` earlier because the fixup commit is going to disappear. # By using `--message`, we can avoid additional typing by only providing the subject. # With the above in mind, let's use Git Rebase to fixup the original commit. # Before we start, pay attention to how I move and change the commits. # We'll discuss more after the rebase is complete: git rebase --interactive
# If you didn't catch all of that, feel free to rewind and watch again. 😉 # Let me explain, though: # 1. The fixup commit was moved to the commit that needed fixing. # 2. "p" (pick) was changed to "f" (fixup) so Git knows to *fix* the commit above it. # 3. We saved and exited to let Git perform our instructions. # Here's the updated Git log: gl # Notice how the fixup commit is gone! # Even better, the original implementation is fixed:
git show # We can test this further by running the implementation: ruby calc.rb 1 2 # Here's what I love about this workflow: # 1. We fixed the original implementation while erasing our mistake. # 2. We avoided editing the commit message because it was an implementation change only. # 3. Reviewers will have a high signal to noise when providing feedback. # 4. Our implementation looks as if it was crafted perfectly the first time. 🎉 # By the way, you can use `git commit --fixup` to speed up this process further. # (we'll cover that in a future screencast, though) # Enjoy! # https://www.alchemists.io # ☿ 🜔 🜍 🜂 🜃 🜁 🜄