23/03/2012

Bazaar revert only one file to previous version

So this was the situation I was recently in:

  • I found that a simulation I was running in Simulink was giving me results that seemed to be wrong
  • I was sure that previously it had given me the right results
  • Therefore I wanted to "roll-back" to the previous version of that Simulink model

I thought this would be a simple and easy thing to do as I have all my files under version control. This sort of procedure is termed "reverting" in version control lingo. It was certainly possible, however it wasn't quite as easy as I expected, so I'll detail the process required.

As noted previously I'm using Bazaar for version control, through both the TortoiseBzr windows interface and also the Bazaar Explorer GUI. Bazaar supports several different methods of undoing mistakes. Through either method of accessing Bazaar you can get at a log of all the commits done on a certain file. From this window you have the option of either "Revert to this revision" or "Update to this revision". Either of these will give you the previous version (although the first one will not count the changes as committed); however they will give you whole of the repository at that revision. This might be useful for pulling out a whole set of software that works together, or establishing the state of an entire project at a particular point, but this is not what I needed.

It is possible to get at an individual file, but it involves a little bit more work. It may also be worth ensuring that the current version is committed in case you later decide that reverting was a mistake. Here is the process:
  1. Look at the log of file to determine what revision number contains the version you want (this is where having written good commit messages will help!)
  2. Make a note of the revision number that you require
  3. Highlight the address of the folder you are in and copy it
  4. Open a command line (on windows go to start - run... - "cmd")
  5. Change to the directory you require by typing "cd " and then pasting the folder address you copied before
  6. Type in the Bazaar revert command as follows:
bzr revert -r num file.ext
where:
num is the revision number that you require (as noted from the log)
file.ext is the filename and extension that you wish to revert to (this could be a list of files if you prefer)

This should give you the previous version of only that file. It will not be committed so you can check that it is the right version and make any changes you want before recommitting.



2 comments:

  1. Bazaar Explorer provides an easier way to revert a single file to a previous revision.

    First open the branch in Bazaar Explorer, then in the working tree right click on the file you wish to revert and select 'Show Log'.

    The log that is displayed will be filtered, showing only revisions in which the file in question was modified. Select the revision you wish to revert the file to.

    In the bottom right of the window will be a file list which indicates which files were modified in this revision. Select the file (which should be in bold text), right click and select 'Revert to this revision'. Confirm the action in the popup window and the file will be reverted.

    In the main explorer window, after a refresh, the file will be displayed as being modified from the current revision.

    If you find that the changes to the file are in fact not responsible for the incorrect Simulink results, you can use revert again (either directly from the working tree or from the menu) and the file will be reverted to the last committed version.


    *Another option which is available is to export the file at the current revision, I use this all the time for my own work and was glad to see it included in recent updates to explorer although it is called 'Save file on this revision as' in the context menu.

    ReplyDelete
    Replies
    1. Thanks for the comment Ryan. I had a feeling that there must be an easier way of achieving this, it just wasn't immediately obvious.

      Delete