Kash Farooq's software development blog

.NET Developer

Renaming files and folders with Bazaar Source Control

Posted by Kash Farooq on September 21, 2009

Following on from Getting started with Bazaar Version Control, now we’ll look at the Holy Grail of Source Control: Renaming files. After all, that’s why we’re ditching Subversion.

A simple file rename

In your BZR controlled local branch, pick a class and use Resharper to rename it (and the .cs).

Run the command:

bzr status

You get output like this:


BZR has found that the project file has changed, one file is missing and that one file has appeared.

Now run the magic move/rename command

bzr move --auto

You get output like this:

myproj/src/MyTest.cs => myproj/src/MyRenamedTest.cs

BZR has worked out (by looking at the contents of the file) that the missing file is in fact the one that has appeared. It has automatically done the rename/move. Remember, it wasn’t just the file that was renamed – the class was renamed too. The files are not identical, but it still worked it out.
If it cannot work it out, you can replace the “auto” option with the actual old and new file paths.

Rename and move a file to a new namespace/folder

Now let’s try something a bit more complex. Create a folder that will host the test classes and add it:

bzr add myproj/src/Tests

Now in dev studio, rename MyRenamedTest.cs back to MyTest.cs, and cut and paste it into the new Tests folder.

Now run the move/rename command again:

bzr move --auto

You get output like this:

myproj/src/MyRenamedTest.cs => myproj/src/Tests/MyTest.cs

Again, BZR has successfully worked out that you’ve renamed and moved a class.

Rename a namespace/folder that already has some files in it

Now, let’s rename folder myproj/src/Tests (which contains MyTest.cs) to myproj/src/UnitTests and check the Bazaar status. Running command:

bzr status

Gives you get output like this:


So, right now, Bazaar thinks you have deleted the Tests folder and its contents, and added a new UnitTests folder.

Let’s fix this by first adding the new UnitTest folder.

bzr add myproj/src/UnitTests --no-recurse


adding myproj/src/UnitTests

Notice the very important no-recurse option. If we had left this option out, Bazaar would have added the folder and the files inside that folder – i.e. it would have added MyTest.cs as a new file, defeating the objective of telling Bazaar about the namespace rename.

Now that we have added the renamed folder, we can run the Bazaar rename command:

bzr move --auto

You get output like this:

myproj/src/Tests/MyTest.cs => myproj/src/UnitTests/MyTest.cs

Bazaar has successfully moved the file from the Tests folder/namespace to the UnitTests folder/namespace.


3 Responses to “Renaming files and folders with Bazaar Source Control”

  1. Eduardo said

    What about rename with bzr mv oldfilename.txt newfilename.txt and to delete with bzr rm filetoberemoved.txt.

  2. RolPasto said

    Thanks for the post. I didn’t know about ‘bzr move –auto’. I renamed an important number of files with ‘rename’ in Linux but I wanted to keep the history for these files. With ‘bzr move –auto’ it is painless.

Sorry, the comment form is closed at this time.

%d bloggers like this: