Hey everyone,
Just a quick hitter on how to designate a file as renamed in Mercurial.
When you move a file to a new directory, or change the name of a file, Mercurial will default to setting the original file as deleted and adding a new file in the new location or with the new name. This remove and add combo does not carry over revision history from the deleted file to the new file. So, if several revisions later you or someone else has questions on how the file was edited in the past, they will have to manually find when the original file was deleted.
If you perform a Mercurial rename, then the new file will contain all the revision history of the original file. For more details on the Mercurial rename command, see: https://selenic.com/hg/help/rename.
Remember the following status codes:
- ! means missing file (repo doesn't know what happened)
- A means added file
- R means removed file
- ? means unknown file (repo doesn't have knowledge of the file yet.)
How to perform a rename using the TortoiseHg Workbench.
- Edit the filename or location of a file recorded in the repository.
- Open TortoiseHg Workbench.
- Right click on the old Filename (has ! mark for status) and click Detect Renames…
- From the dialog Detect Copies/Renames, highlight all files in unrevisioned files that were renames or moved.
- Set a Min Similarity percent (the lower the number, the more different the files can be and still match)
- Select Find Renames
- Under Candidate Matches, select correct matches and click Accepted Matches.
- Close the Dialog Detect Copies/Rename dialog.
- Add the newly created entries into the commit (each file will have a status R for a removed file and a status A for an added file.)
- Commit as usual.
Alternate method - Was Renamed From
Alternatively, you can perform a rename by right clicking on the new filename (has a ? mark) and selecting Was renamed from….
I find using the heavier Detect Copies/Rename procedure easier if many renames are made. I find using the quicker Was renamed from… procedure easier for one or two renames.