Dropping Commits With Git Rebase
I've been warned enough times about the potential dangers of git reset --hard ...
that I always second guess myself as I type it out. Is it git reset --hard HEAD
or git reset --hard HEAD~
?
If the working directory and index are clean, then there is another way to remove commits. A way that gives me more confidence about what exactly is being removed.
Doing an interactive rebase gives you a number of options. One of those options is d
(which stands for drop
).
This pulls up an interactive rebase with all commits going back to what is on master -- great for when working from a feature branch.
Adding d
next to the commits you want to get rid of and saving will drop those commits. The great part is that there is zero ambiguity about which ones are being dropped.
h/t Jake Worth
Last updated