Reverting, updating a previous commit
- Save and stash your work.
- 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.
- Start the interactive rebase process, pasting in the characters from the ID:
git rebase --interactive ID^
- Your editor will come up with several lines like
pick d3adb33 Commit message, one line for each commit since the older one.
- Change the word “
pick” to “
edit” in front of the commit you want to change.
- Save and quit.
- Edit your project files to make the correction, then run
git commit --all --amend.
- After you’ve committed the fixed version, do
git rebase --continue.
- 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.
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 bihencomments powered by Disqus