我没有在我的开发计算机上设置用户名并进行了一些提交。我可以追溯更改用户名,以便清楚谁提交了这些变更集吗?
4 回答
如果您尚未发布存储库,那么这应该不会太难。您需要使用Convert 扩展至 Mercurial,它可以让您“过滤”现有存储库以创建新存储库。--authors 开关允许您在每个提交被过滤时编辑作者。
如果您已经发布了您的存储库,请考虑对您的用户的影响,mercurial wiki 有一些理由不编辑历史。
通过将这些行添加到您的 .hgrc 来启用扩展:
[extensions]
hgext.convert=
编写一个文件以将旧名称映射到新名称(authors.convert.list):
user@ubuntu=real.name@my.example.com
运行转换:
hg convert --authors authors.convert.list SOURCE DEST
我刚刚检查过,它对我有用:)。
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.
我尝试了几种不同的方法(包括Convert Extension,我发现它创建了一个不相关的存储库)。使用 MQ 编辑历史的 Mercurial wiki 说明是我发现最有帮助的。(当然,对于编辑任何公开的历史记录是一个坏主意,通常有一些警告,但只有您拥有的本地变更集可以编辑)。
我将在这里总结关键步骤,并阐明更改作者的机制。假设第一个错误的作者提交是在修订版BAD
(当然你还没有在任何地方发布你的更改),你应该能够执行以下操作(我假设你在存储库根目录):
通过将其添加到 $HOME/.hg/hgrc 来启用 MQ
[extensions]
hgext.mq=
将最近的变更集转换为补丁:
$ hg qimport -r BAD:tip
(现在可以在 找到它们.hg/patches
)
“取消应用”所有补丁(假设它们已被应用,并反转它们),以使您的存储库进入修订之前的状态BAD
:
$ hg qpop -a
如果你查看你的补丁,你会发现作者在所有补丁中都被编码在一种注释行中:
$ 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.
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.