Search code examples
bazaar

How to retrieve branch whose tree has been removed and deleted?


I have a bazaar repository holding several branches. I recently removed one of the trees with bzr remove-tree path/to/branch followed by rm -r path/to/branch. Now if I understand correctly, the repository should still hold the branch history, since I never did bzr remove-branch. However, I can't figure out how to retrieve the branch to continue working on it. Can someone help?


Solution

  • You can use bzr heads --dead to see the heads (= most recent revisions) of deleted branches, including their global revision ids.

    You can then do:

    bzr branch -r REVISION_ID REPO_DIR BRANCH_DIR
    

    Here, REVISION_ID is the id of the head that you want to restore, REPO_DIR is the directory that holds the repository, and BRANCH_DIR is the directory where you want the branch to be stored.

    Edit: If the above doesn't work for some reason, you can also do:

    bzr init BRANCH_DIR
    cd BRANCH_DIR
    bzr pull -r REVISION_ID .
    

    BRANCH_DIR must be underneath the repository directory, of course.