Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: Change username of some commits not pushed yet?

I made a few commits, but I realised later on that I haven't had my username setup properly. I changed it and made a few more commits with the right username. Is there any way to change the first commits to use the new username before pushing all of them?

like image 920
confused00 Avatar asked Nov 21 '25 22:11

confused00


1 Answers

Here's how I would accomplish your goal, it relies on mq extension, Mercurial's patch queue. (Updated to include @MarkTolonen's fantastic comment!)

Step 0. Back up your work! (you can create a local throw-away clone to try this out)

  1. Enable the mq extension in your config files (see help here)
  2. use hg qimport to import into the patch queue the changesets you want to edit
  3. use hg qpop -a to pull those patches off the applied patch stack
  4. push the first patch on with hg qpush
  5. use hg qref -U to update the patch's author to the current user (or use hg qref -u <username> to set it explicityly)
  6. repeat steps 4. and 5. for each patch in the queue.
  7. double check your work - Is your username appearing correct in the log now?
  8. use hg qfin -a to finalize the patches into changesets
  9. you should now be ready to push the updated changesets to the public repo

My original steps included manually setting the user in a text editor, which were in place of steps 4-6 above:

A. open the folder .hg\patches, you should have a ###.diff file for each changeset
B. open those in the text editor of your choice
C. edit the line at the top that starts with # User <your old user name>
and update it to be # User <your new user name>
D. save the patches
E. use hg push -a to push them back onto the applied stack

like image 55
Edward Avatar answered Nov 24 '25 22:11

Edward