|
| 1 | +==== Bazaar |
| 2 | +(((Bazaar)))(((Importing, from Bazaar))) |
| 3 | + |
| 4 | +Bazaar is a DVCS tool much like Git, and as a result it's pretty straightforward to convert a Bazaar repository into a Git one. |
| 5 | +To accomplish this, you'll need to import the `bzr-fastimport` plugin. |
| 6 | + |
| 7 | + |
| 8 | +===== Getting the bzr-fastimport plugin |
| 9 | + |
| 10 | +The procedure for installing the fastimport plugin is different on UNIX-like operating systems and on Windows. |
| 11 | +In the first case, the simplest is to install the `bzr-fastimport` package that will install all the required dependencies. |
| 12 | + |
| 13 | +For example, with Debian and derived, you would do the following: |
| 14 | +[source,console] |
| 15 | +---- |
| 16 | +$ sudo apt-get install bzr-fastimport |
| 17 | +---- |
| 18 | + |
| 19 | +With RHEL, you would do the following: |
| 20 | +[source,console] |
| 21 | +---- |
| 22 | +$ sudo yum install bzr-fast-import |
| 23 | +---- |
| 24 | + |
| 25 | +With Fedora, since release 22, the new package manager is dnf: |
| 26 | +[source,console] |
| 27 | +---- |
| 28 | +$ sudo dnf install bzr-fastimport |
| 29 | +---- |
| 30 | + |
| 31 | +If the package is not available, you may install it as a plugin: |
| 32 | +[source,console] |
| 33 | +---- |
| 34 | +$ mkdir --parents ~/.bazaar/plugins/bzr # creates the necessary folders for the plugins |
| 35 | +$ cd ~/.bazaar/plugins/bzr |
| 36 | +$ bzr branch lp:bzr-fastimport fastimport # imports the fastimport plugin |
| 37 | +$ cd fastimport |
| 38 | +$ sudo python setup.py install --record=files.txt # installs the plugin |
| 39 | +---- |
| 40 | + |
| 41 | +For this plugin to work, you'll also need the `fastimport` Python module. |
| 42 | +You can check whether it is present or not and install it with the following commands: |
| 43 | +[source,console] |
| 44 | +---- |
| 45 | +$ python -c "import fastimport" |
| 46 | +Traceback (most recent call last): |
| 47 | + File "<string>", line 1, in <module> |
| 48 | +ImportError: No module named fastimport |
| 49 | +$ pip install fastimport |
| 50 | +---- |
| 51 | +If it is not available, you can download it at address https://pypi.python.org/pypi/fastimport/. |
| 52 | + |
| 53 | +In the second case (on Windows), `bzr-fastimport` is automatically installed with the standalone version and the default installation (let all the checkboxes checked). |
| 54 | +So in this case you have nothing to do. |
| 55 | + |
| 56 | +At this point, the way to import a Bazaar repository differs according to that you have a single branch or you are working with a repository that has several branches. |
| 57 | + |
| 58 | +===== Project with a single branch |
| 59 | + |
| 60 | +Now `cd` in the directory that contains your Bazaar repository and initialize the Git repository: |
| 61 | +[source,console] |
| 62 | +---- |
| 63 | +$ cd /path/to/the/bzr/repository |
| 64 | +$ git init |
| 65 | +---- |
| 66 | + |
| 67 | +Now, you can simply export your Bazaar repository and convert it into a Git repository using the following command: |
| 68 | +[source,console] |
| 69 | +---- |
| 70 | +$ bzr fast-export --plain . | git fast-import |
| 71 | +---- |
| 72 | + |
| 73 | +Depending on the size of the project, your Git repository is built in a lapse from a few seconds to a few minutes. |
| 74 | + |
| 75 | +At this point, the `.git` directory and your working tree are all set up, but Git's index isn't synchronised with the working tree: |
| 76 | +[source,console] |
| 77 | +---- |
| 78 | +$ git status |
| 79 | +On master branch |
| 80 | +Changes that will be validated: |
| 81 | + (use "git reset HEAD <fichier>..." to unstage) |
| 82 | +
|
| 83 | + removed : .bzrignore |
| 84 | + removed : file.txt |
| 85 | +
|
| 86 | +Untracked files: |
| 87 | + (use "git add <fichier>..." to include in what will be validated) |
| 88 | +
|
| 89 | + .bzr/ |
| 90 | + .bzrignore |
| 91 | + file.txt |
| 92 | +---- |
| 93 | +Type this to fix that: |
| 94 | +[source,console] |
| 95 | +---- |
| 96 | +$ git reset HEAD . |
| 97 | +---- |
| 98 | + |
| 99 | +Now let us have a look at the files to ignore. |
| 100 | +As `.bzrignore`'s format is completely compatible with `.gitignore`'s format, the simplest is to rename your `.bzrignore` file: |
| 101 | +[source,console] |
| 102 | +---- |
| 103 | +$ git mv .bzrignore .gitignore |
| 104 | +---- |
| 105 | + |
| 106 | +Then you have to create a commit that contains this change for the migration: |
| 107 | +[source,console] |
| 108 | +---- |
| 109 | +$ git commit -am 'Migration from Bazaar to Git' |
| 110 | +---- |
| 111 | + |
| 112 | +That's all! |
| 113 | +Now you can push the repository onto its new home server: |
| 114 | +[source,console] |
| 115 | +---- |
| 116 | +$ git remote add origin git@my-git-server:mygitrepository.git |
| 117 | +$ git push origin --all |
| 118 | +$ git push origin --tags |
| 119 | +---- |
| 120 | + |
| 121 | +===== Case of a project with a main branch and a working branch |
| 122 | + |
| 123 | +You can also import a Bazaar repository that contains branches. |
| 124 | +Let us suppose that you have two branches: one represents the main branch (myProject.trunk), the other one is the working branch (myProject.work). |
| 125 | +[source,console] |
| 126 | +---- |
| 127 | +$ ls |
| 128 | +myProject.trunk myProject.work |
| 129 | +---- |
| 130 | + |
| 131 | +Create the Git repository and `cd` into it: |
| 132 | +[source,console] |
| 133 | +---- |
| 134 | +$ git init git-repo |
| 135 | +$ cd git-repo |
| 136 | +---- |
| 137 | + |
| 138 | +Pull the master branch into git: |
| 139 | +[source,console] |
| 140 | +---- |
| 141 | +$ bzr fast-export --export-marks=../marks.bzr ../myProject.trunk | \ |
| 142 | +git fast-import --export-marks=../marks.git |
| 143 | +---- |
| 144 | + |
| 145 | +Pull the working branch into Git: |
| 146 | +[source,console] |
| 147 | +---- |
| 148 | +$ bzr fast-export --marks=../marks.bzr --git-branch=work ../myProject.work | \ |
| 149 | +git fast-import --import-marks=../marks.git --export-marks=../marks.git |
| 150 | +---- |
| 151 | + |
| 152 | +Now `git branch` shows you the `master` branch as well as the `work` branch. |
| 153 | +Check the logs to make sure they’re complete and get rid of the `marks.bzr` and `marks.git` files. |
| 154 | + |
| 155 | +Your Git repository is ready to use. |
0 commit comments