From your question, I think you want something like this.
git-rebase(1) does exactly that. 
$ git rebase -i HEAD~5
git awsome-ness contains an example.
- Don't use git-rebaseon public (remote) commits.
- Make sure your working directory is clean (commitorstashyour current changes).
- Run the above command. It launches your $EDITOR.
- Replace pickbeforeCandDbysquash. It will meld C and D into B. If you want to delete a commit then just delete its line.
If you are lost, type:
$ git rebase --abort  
However, to copmress the .git folder safely, the above is not recommended. You can try the following as mentioned in a comment by Linus.
git repack -a -d --depth=250 --window=250
where that depth thing is just about how deep the delta chains can be (make them longer for old history - it's worth the space overhead), and the window thing is about how big an object window we want each delta candidate to scan.