Revert a deleted file several commits later
Solution 1:
I found this solution on another website, but I can't find where.
The answer is to revert the files that were deleted individually:
hg revert -rxxx filename
where xxx
is the revision number of before the delete.
Then commit them back in. The history is preserved!
Solution 2:
Step 1: Find the revision that deleted the file
$ hg log -r "removes('filename')"
changeset: 1725:28bee50c5fe4
…
Step 2: Clean revert of the file to one revision prior
$ hg rev -r 1724 -C filename
The -C
(clean) or --no-backup
option ensures that the file receives the exact same file name, without any revision number addendum.