5

I was supposed to perform subtree pull --squash for a third-party module that my project depends on, but I accidentally forgot to put --squash. Now my project commit history is flooded with the third-party module commits. They are scattered all over the log.

This mess needs to be gone. How would I identify all the commits that belongs to the third-party module, squash them into one, and then purge them from my project history, if possible at all?

More info:

Note that I have done several commits, that I intend to keep, after the broken operation.

tamakisquare
  • 16,659
  • 26
  • 88
  • 129

1 Answers1

7
  1. Use git reflog to find your project's state from before you did the broken operation.
  2. Check out that hash or git reset --hard to it.
  3. Redo the operation with the correct flags.
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • Thanks Carl. My situation, however, is a bit more complicated. I have done several commits, which need to be kept, after the broken operation. How can I undo the broken operation while selectively keeping some commits that happened after the broken operation? – tamakisquare Sep 10 '13 at 20:41
  • 2
    Do you know which commits are yours? Just cherry pick or rebase them after you fix things up. – Carl Norum Sep 10 '13 at 20:42
  • 1
    For deleting the commits that are left over from the unsquashed operation try this: [Garbage Collect Commits in Git](http://stackoverflow.com/questions/14991916/garbage-collect-commits-in-git) – Maic López Sáenz Sep 11 '13 at 18:36
  • @LopSae - Appreciate the tip. I was head-scratching on how to deal with that. – tamakisquare Sep 11 '13 at 20:19
  • I completely know the feeling :) – Maic López Sáenz Sep 11 '13 at 23:45