diff --git a/README.md b/README.md index ffb46fe..f2af2c3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_687 TILs and counting..._ +_688 TILs and counting..._ --- @@ -167,6 +167,7 @@ _687 TILs and counting..._ - [Delete All Untracked Files](git/delete-all-untracked-files.md) - [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md) - [Diffing With Patience](git/diffing-with-patience.md) +- [Dropping Commits With Git Rebase](git/dropping-commits-with-git-rebase.md) - [Dry Runs in Git](git/dry-runs-in-git.md) - [Excluding Files Locally](git/excluding-files-locally.md) - [Find The Initial Commit](git/find-the-initial-commit.md) diff --git a/git/dropping-commits-with-git-rebase.md b/git/dropping-commits-with-git-rebase.md new file mode 100644 index 0000000..e7f2cbc --- /dev/null +++ b/git/dropping-commits-with-git-rebase.md @@ -0,0 +1,32 @@ +# 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`). + +``` +$ git rebase -i master +``` + +This pulls up an interactive rebase with all commits going back to what is +on master -- great for when working from a feature branch. + +``` +pick 71ed173 Add Create A Stream From An Array as a reasonml til +pick 80ac8d3 Add some clarity by distinguishing var names +d 4f06c32 Add Data Structures With Self-Referential Types as a reasonml til +d 01a0e75 Fix the name of this file +``` + +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