I have accidentally made a commit to my local repository. To be more specific, I committed changes to lots of files all at once, when I meant to commit them one at a time. <
What I'd do in this situation is make a new branch that has the changes I want before I ever thought about removing the bad change-set. So in this case I'll need to go back to the revision before I made the bad commit, re-do my changes and then make multiple commits, one for each file.
Step by step:
1) Go back to before the bad commit.
% cd
% hg log -l 5
% hg update -r
2) Remake the changes: I'd get a patch which describes the changes I want, and apply it to the tree. (I'm assuming tip currently points to where we started)
% hg diff -r .:tip | patch -p1
patching file a/b/c/d
patching file a/b/e/f
3) Make new commits: We're now back at the state before you made the commit you wanted to split up. Do hg status
and look at the modified files, make sure everything is as you expect. At this point you can either commit the files one by one by naming them on the command line, or use an extension like record
or crecord
to interactively select them.
% hg commit a/b/c/d
% hg commit a/b/e/f
...or...
% hg crecord
You'll end up with a repo that looks like this:
o----o----B
\
\
--o----o----o----T
Where B is the old bad commit, and T is the new tip of the repo. If you want to then make that branch as closed, so it doesn't show up in logs / etc, you can...
% hg update -r
% hg commit --close_branch
% hg update -r tip
If you want to remove it completely, you can strip it.
% hg strip -r
Either way, your log will look like nothing ever happened.