8

So I started down a new branch of development and decided that some files needed to go.

Several commits later I realise that a certain decision was wrong and I need a couple of the files back.

My initial thought of how to get the files back is to just take copies from the other branch and commit them to the head of the new branch, but I worry that this means that the files won't be associated with their old history.

Is there a way to do this that keeps the history intact?

I'm using mercurial version 1.5.2

DavidPostill
  • 162,382

2 Answers2

10

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!

1

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.