The letter A styled as Alchemists logo. lchemists
Published April 10, 2020 Updated April 10, 2020

Git Rebase Drop

Demonstrates how to delete commits when rebasing.


# Hello and welcome to the Alchemists Screencasts!
# Today, we'll learn about Git Rebase Drop.
# For context, here's a few Ruby scripts we've been working on:


# ℹī¸ `l` is aliased to `ls -alhT`.

# Notice the `add.rb` and `multi.rb` scripts.
# Here's the associated commit:



# 💡 See the *Git Log Pretty* screencast to learn more about the `gl` alias.
# ℹī¸ `ghow` is a fancy function for `git show` but will gloss over that for now.

# Turns out we don't need the `multi.rb` implementation, only `add.rb`.
# This is where using Git Rebase Drop can help:

git rebase --interactive

# If you didn't catch all of that, feel free to rewind and watch again. 😉
# Let me explain, though:
# 1. "p" (pick) was changed to "d" (drop) so Git knows to *drop* the commit.
# 2. We saved and exited to let Git perform the instruction.
# 3. Git then deleted the commit we marked as *drop*.
# To confirm:


# Notice the commit with the `multi.rb` implementation is gone. 🎉
# What if there was an alternative way to dropping commits, though?
# Well, you're in luck, there is.
# To demonstration, I'll need to restore the original commit via Git Reflog:

git reflog

# We don't have time, during this screencast, to explain Git Relog more. 😅
# Just know it's a powerful tool for debugging or fixing local mistakes. 😉
# In this case, we only need to restore our history before the rebase:

git reset --hard

# Notice I picked the SHA prior to the rebase.
# Also notice the "multiplication" implementation commit is back. 🎉
# Great, now we can rebase again by dropping that commit.
# We'll do this via deleting the line entirely:

git rebase --interactive

# 💡 See the *Git Rebase Pick* screencast for adding lines (i.e. opposite of the above).
# Due to deleting the line with the commit we didn't need, it is now gone:


# This can be a faster way to remove several commits you don't need.
# Now you have two solutions for dropping commits you no longer need. 🎉

# Enjoy!
# â˜ŋ 🜔 🜍 🜂 🜃 🜁 🜄