6

At the moment I am looking at transitioning from subversion to Mercurial at work, and as such the Mercurial repository is not yet published.

I have used the authormap argument to transform our usernames to the Mercurial format, which went fine.

Unfortunately two people have been commiting under the same name. The repository is not very large, so I would like to change the authors to match the right people. For that reason I would like to ask:

Is there any way to change the author for a specific changeset, or a list of changesets?

FrederikNS
  • 5,562
  • 2
  • 22
  • 36
  • If you have access to the author email for each revision in the SVN repo, couldn't you use the couple (name,email) in your authormap for the migration, generating different author name on the Mercurial repo? Otherwise: http://stackoverflow.com/questions/732819/can-i-change-the-username-on-a-mercurial-changeset – VonC Feb 01 '12 at 11:29
  • Unfortunately no, both have been committing under the same username (one of the users initials). The only thing that differentiates them is the files worked on, and maybe the IP address of the committers. – FrederikNS Feb 01 '12 at 13:28
  • That seems tricky, then. – VonC Feb 01 '12 at 13:37

2 Answers2

8

You can use the bundled extension Mercurial Queues (MQ) to change commit authors. Note that MQ will only work as long as history is linear. If there are branches you need to first rebase them off to a temporary side branch, and then after editing rebase them back.

First qimport the changes up till the first changeset you want to modify:

hg qinit
hg qimport -g -r <first-revnr>:tip

Then use qpop or qgoto to navigate to the respective changesets:

hg qgoto <revnr>.diff

And then use qrefresh to change the user info on the currently active changeset:

hg qrefresh -u "Some User <user@example.com>"

You can verify with hg log whether the user was correctly updated. After this, repeat for all other changesets.

When you are done, qpush all patches and use qfinish to finalize the repository.

hg qpush -a
hg qfinish -a
Laurens Holst
  • 20,156
  • 2
  • 29
  • 33
  • I had some slight troubles. Just remember to run a `hg update` starting. I did it on a clean repository, with no files in the working copy, which yielded errors – FrederikNS Mar 20 '12 at 22:00
2

You could as well use the evolve extension. After setting up the extension

hg amend -U && hg prev

for a stack of commits and then hg evolve --all at the end.

Evolve introduces a meta-graph that says which commit replaces which commit. So when we do hg amend -U a bunch of times, we create commits with a different author that replaced the old commits. hg evolve --all the will use the replacement information to figure out where to move commits that were based on our pre-replaced commits.

Credits to mercurial developers on IRC #mercurial.

Arun
  • 1,399
  • 12
  • 21