I didn\'t set the username on my development computer and made a few commits. Can I retroactively change the username so it\'s clear who committed these changesets?
I've tried a couple of different methods (including the Convert Extension, which I found created an unrelated repository). The Mercurial wiki instructions for editing history using MQ were the ones I found most helpful. (There are of course the usual caveats about editing any publicly-known history being a bad idea, but local-changesets that only you have are OK to edit).
I'll summarise the crucial steps here, and clarify the mechanics of changing the author. Assuming the first wrong author commit is at revision BAD
(and you haven't published your changes anywhere of course), you should be able to do the following (I'll assume you're at the repository root):
Enable MQ by adding this to $HOME/.hg/hgrc
[extensions]
hgext.mq=
Convert the recent changesets into patches:
$ hg qimport -r BAD:tip
(They can now be found at .hg/patches
)
"Unapply" all the patches (assume they've been applied, and reverse them), to get your repository into the state of the revision before BAD
:
$ hg qpop -a
If you look at your patches, you'll see that the author is encoded in a kind of comment line in all the patches:
$ grep User .hg/patches/*
.hg/patches/102.diff:# User Firstname Lastname <f.lastname@oops.wrongurl.example.com>
Now use your favourite search/replace tool to fix the patches (I'm using Perl here). Let's assume you want the commit name to be f.lastname@righturl.example.com
:
$ perl -pi -e 's/f\.lastname\@oops\.wrongurl\.example\.com/f.lastname\@righturl.example.com/' .hg/patches/*.diff
Now check that you have successfully changed the author name, and re-apply the patches:
$ hg qpush -a
Then convert the applied patches into proper changesets:
$ hg qfinish -a
And you're done. Your repository is still listed as related, so you won't get any complaints about pushing.
If you've not published your repository then this shouldn't be too hard. You need to use the Convert extension to Mercurial, which will let you 'filter' your existing repository to create a new one. the --authors switch lets you edit the author for each commit as it is filtered.
If you have published your repository, please consider the impact on your users, the mercurial wiki has some reasons not to edit history.
Enable the extension by adding these lines to your .hgrc:
[extensions]
hgext.convert=
Write a file to map the old name to the new name (authors.convert.list):
user@ubuntu=real.name@my.example.com
Run the conversion:
hg convert --authors authors.convert.list SOURCE DEST
I just checked it, it works for me :).
If you have a single outgoing changeset, there is a very simple way to do this:
$ hg ci --amend --user "My Name <mymail@example.org>" -X "**"
The -X "**"
option can be omitted if you don't have any local changes.
I've used the histedit
extension which allowed me to change the author without making new repos like "convert" would or resorting to "mq".
First, in your Mercurial config file, make sure your username is set correctly and enable the histedit extension:
[ui]
username = Your Name <your.name@domain.org>
[extensions]
histedit =
Then, if you want to change revision 40, use:
hg histedit -r 40
In the file that appears, on the line corresponding to revision 40, change the word pick
to edit
. Save and close the file.
Now, hg commit
. You'll need to re-enter your commit message and save.
Finally, hg histedit --continue
.
The commit will appear with your new username
. A side-effect is the timestamp of the commit is also updated.