One easy (but slow) way to do this is with git filter-branch and --prune-empty . Without other filters, no other commits will be changed, but any empty ones will be discarded (which will lead to the fact that all subsequent commits will have new parent identifiers and, therefore, still “overwrite the history”: it does not matter if this is your original import from hg in git, but it's a big deal if others use this repository already).
Pay attention to all the usual caveats with a filter branch. (Also, as a side note, an “empty commit” actually has one that has the same tree as the previous one: it's not that it has no files at all, it has all the same files with the same modes, and same contents as its parent commit. This is because git stores the full snapshots for each commit, and not the difference from one commit to the next.)
Here is a tiny example that hides many places where you can do more interesting things:
$ ... create repository ... $ cd some-tmp-dir; git clone
(This first clone step is for security: filter-branch can be pretty damaging, so it’s always useful to start it with a new clone, not the original. Using --mirror means that all its branches and tags are mirrored in this copy, too. )
$ git filter-branch --prune-empty --tag-name-filter cat -- --all
(Now wait a very long time, see the documentation for the methods to speed this up a bit.)
$ git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
(This step is copied from the documentation: it discards all source branches before running the filter. In other words, it makes the filtering permanent. Because it is a clone that is safe enough even if the filter goes wrong.)
$ cd third-tmp-dir; git clone --mirror file://path-to-filtered-tmp
(This makes a clean, beautifully compressed copy of the filtered copy, with no remaining objects in the filtering stages.)
$ git log
Once you are sure that the clone of the filtered clone is good, you do not need the filtered clone and it can use the last clone instead of the first. (That is, you can replace the "true original" with the final clone.)