Friday, 1 June 2012

Everybody already knows about commit squashing in Git. What's less known is the new --autosquash feature in Git 1.7. There is a nice article about this in Technosorcery. What I do wonder about this is the whole point of "squash" because you need to have exactly the same comment (or start of) as the one you want to squash into.

So the difference between squash and fixup is that the latter doesn't add the same commit message twice, so why would I want to use squash? It would make sense if it could have some other message, now you probably just delete the message?

Well, so I was doing some squashing in a repository when I managed to mess things up. It was early in the morning, mind.. what I did was to squash commits to a commit I had already published, and this is obviously a big no-no.

Yeah, I hadn't quite figured out how to use fixup at that point either. Resetting to ORIG_HEAD didn't help, but using a combination of reflog & reset --hard did the trick and my commit history was back to what it was before my mistake.

Btw, if you want to see the reflogs but want a nicer output (which lacks some of the stuff) you can also say "git log -g".