views:

581

answers:

3

Hi everybody !

I'd like to know if it is possible to restore a removed file from an older revision (a clean way to do it)

I've renamed a file for some tests, than I commited all my work (and I forgot to rename the file) and did a lot of other commits... When I realised, it was too late...

Regards, Ayman

A: 

This isn't the best answer. See bialix' answer which is a lot simpler. I'll leave this here just for reference.


Here's what I think is the cleanest method:

  1. Create a branch:

    bzr branch mytree repair-path

  2. cd into the repair branch

  3. Revert just the missing file at its last revision (eg 287 in this example):

    bzr revert -r 287 lost.file

  4. Commit the change

    bzr commit -m "Unshoot my foot"

  5. cd back into the main branch

  6. merge in the repair

    bzr merge repair-path

  7. When ready, commit the merge and delete the repair branch.

You could do this just by reverting in the original working branch, but it's probably good practice not to. You also need to worry (just a little) about any uncommitted changes.

Brent.Longborough
+1  A: 

If you know revision number when you removed that file (you can inspect history with bzr log -v) then you can resurrect that file with merge command. So for file foo and revision number N you need to run command:

bzr merge foo -r N..N-1

E.g. for revision 287:

bzr merge foo -r 287..286

This command will restore your file as in revision 287. You need to commit this change and you done.

bialix
Careful! This will undo the *whole* of rev 287. I don't think you can merge just one specific file from a changeset.
Brent.Longborough
Yes, bzr can merge only one file from changeset. You can test it yourself.
bialix
Yes, you're absolutely right. +1. I withdraw my comment and my answer.The only thing I would still maintain is that, depending on the complexity of your work, it might be sensible to revert in another branch.
Brent.Longborough
I tried this, but bzr told me it was a non versioned file...I found another solution: the undelete plugin !
kamou
That may have been because you recreated the same file name before doing the merge, thereby causing a conflict?
Brent.Longborough
Or you may have misspelt the filename? (Sorry...)
Brent.Longborough
yes, tou were right, I recreated the file... :)
kamou
+2  A: 

The easiest way is to simply use bzr revert with a revision number before the file was deleted:

bzr revert -rX path/to/file
bzr commit -m 'Bringing path/to/file back'

You don't need to merge anything.

Lukáš Lalinský