1. Save and stash your work.
  2. Look at git log and copy the first 5 or so characters from the ID of the commit you want to edit onto your clipboard.
  3. Start the interactive rebase process, pasting in the characters from the ID: git rebase --interactive ID^
  4. Your editor will come up with several lines like pick d3adb33 Commit message, one line for each commit since the older one.
  5. Change the word “pick” to “edit” in front of the commit you want to change.
  6. Save and quit.
  7. Edit your project files to make the correction, then run git commit --all --amend.
  8. After you’ve committed the fixed version, do git rebase --continue.
  9. Git will do its magic, recreating all the commits since then.

You might need to resolve some conflicts, if the change you made affected later commits. Follow Git’s instructions to resolve those.

Once the rebase is done, re-apply the stash.

source: http://blog.jacius.info/2008/6/22/git-tip-fix-a-mistake-in-a-previous-commit/

Those steps are copy/pasted as a quick note reminder for myself and are not meant to steal/harm the original author writing.

Created on 14-06-2010 by Eric le bihen

comments powered by Disqus