10

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

Matthew
  • 28,056
  • 26
  • 104
  • 170
Ayman Khamouma
  • 976
  • 10
  • 24

3 Answers3

13

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ý
  • 40,587
  • 6
  • 104
  • 126
4

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
  • 20,053
  • 8
  • 46
  • 63
0

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
  • 9,567
  • 10
  • 42
  • 62