I agree with websterridge, modifying history is probably not the way to go; that only makes sense if you want to permanently erase all traces of the old commit (and has its set of problems).
The best solution is probably to create a new commit with the necessary changes. The idea is to create a diff between the version that was committed, and the version that should have been, and apply that diff to the current version.
You could do it like this (untested):
- Create (and check out) a branch on top of the old commit where the wrong code was committed:
git checkout -b fix-branch SHA_OF_OLD_COMMIT
- Copy the right version of the code that should have been committed into the working directory. You can just overwrite the wrong files without worrying about conflicts, because you have gone back to the old commit with the original code import.
- Commit this:
git add --all . ; git commit -m "Fix import of wrong code."
Now you have the right code in git, but on branch "fix-branch".
You can now use git's tools to get the right code into your current branch (let's say master): either rebase fix-branch on top of master, or merge it into master.
In this case a merge is probably better, because that way the repository history contains the original version of the new, correct code import before conflict resolution.
Either way, you'll probably get a lot of conflicts, but there's no way around this.
Good luck!