0

I made a commit that was incomplete, so I want to delete it and add those changes to a new commit I'm creating right now. The problem is, there are multiple other commits between then and now that I want to keep, so reset won't work.

How do I remove this small commit as if I never made it, but everything else after it still remains?

davidtgq
  • 3,780
  • 10
  • 43
  • 80
  • 1
    There's no commit that's too small to be worth being a commit. Generally, preserving history is the most important bit; thus, to "undo" a commit, you make an inverse commit with `git revert xxxxxxx` (which will be of roughly the same size as the original commit you're reverting). – Amadan Jun 06 '18 at 07:59
  • @Amadan I'm aware of that. I'm certain that I want to delete it. – davidtgq Jun 06 '18 at 08:00
  • 1
    What you want is `git rebase -i`, not `git revert`. Change the commit after it to `squash` instead of `pick`. I agree that history rewriting is dangerous, and if you `push`ed it anywhere it is more complicated and *just not worth rewriting history*, but it can be useful if the history is so far only private. – Daniel H Jun 06 '18 at 08:03
  • 1
    @DanielH Yes, but `drop`, not `squash`. `squash` will meld it to the adjacent commit; `drop` will make it as if it was never made. – Amadan Jun 06 '18 at 08:04
  • @Amadan My impression is that the OP wants the trees of all the later commits to be the same, and just wants it to be as though they skipped running `git commit`, not skipped making those changes. – Daniel H Jun 06 '18 at 08:05
  • @DanielH correct, I want to put those changes in a new commit that I'm making right now (not merge them with another previous commit). And it is a solo repository, so no worries about rewriting history - I wouldn't do this on remote where others may have already pulled. – davidtgq Jun 06 '18 at 08:07
  • 1
    Note that you can also just reorder the lines inside the interactive rebase, bring the commit you want to the bottom (without changing anything else - no `drop` and no `squash`), and that will effectively "move" the commit to the end of your history, just like you want it. Of course, if you get conflicts... gods help ye :P – Amadan Jun 06 '18 at 08:11
  • @Amadan That's a more succinct way to get the result I wanted. Phrasing it this way also yielded more relevant search results, thanks for the idea :) – davidtgq Jun 06 '18 at 08:18

0 Answers0