Skip to content

Commit 6c2bf8a

Browse files
authored
Merge pull request #728 from aollier/fix
Bazaar
2 parents 2c500ad + c34d108 commit 6c2bf8a

File tree

1 file changed

+39
-45
lines changed

1 file changed

+39
-45
lines changed

book/09-git-and-other-scms/sections/import-bzr.asc

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@
44
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.
55
To accomplish this, you'll need to import the `bzr-fastimport` plugin.
66

7-
87
===== Getting the bzr-fastimport plugin
98

109
The procedure for installing the fastimport plugin is different on UNIX-like operating systems and on Windows.
1110
In the first case, the simplest is to install the `bzr-fastimport` package that will install all the required dependencies.
1211

1312
For example, with Debian and derived, you would do the following:
13+
1414
[source,console]
1515
----
1616
$ sudo apt-get install bzr-fastimport
1717
----
1818

1919
With RHEL, you would do the following:
20+
2021
[source,console]
2122
----
2223
$ sudo yum install bzr-fast-import
2324
----
2425

2526
With Fedora, since release 22, the new package manager is dnf:
27+
2628
[source,console]
2729
----
2830
$ sudo dnf install bzr-fastimport
2931
----
3032

3133
If the package is not available, you may install it as a plugin:
34+
3235
[source,console]
3336
----
3437
$ mkdir --parents ~/.bazaar/plugins/bzr # creates the necessary folders for the plugins
@@ -40,6 +43,7 @@ $ sudo python setup.py install --record=files.txt # installs the plugin
4043

4144
For this plugin to work, you'll also need the `fastimport` Python module.
4245
You can check whether it is present or not and install it with the following commands:
46+
4347
[source,console]
4448
----
4549
$ python -c "import fastimport"
@@ -58,88 +62,51 @@ At this point, the way to import a Bazaar repository differs according to that y
5862
===== Project with a single branch
5963

6064
Now `cd` in the directory that contains your Bazaar repository and initialize the Git repository:
65+
6166
[source,console]
6267
----
6368
$ cd /path/to/the/bzr/repository
6469
$ git init
6570
----
6671

6772
Now, you can simply export your Bazaar repository and convert it into a Git repository using the following command:
73+
6874
[source,console]
6975
----
7076
$ bzr fast-export --plain . | git fast-import
7177
----
7278

7379
Depending on the size of the project, your Git repository is built in a lapse from a few seconds to a few minutes.
7480

75-
At this point, the `.git` directory and your working tree are all set up, but the working tree and the index are not synchronized with HEAD:
76-
77-
[source,console]
78-
----
79-
$ git status
80-
On master branch
81-
Changes that will be validated:
82-
(use "git reset HEAD <fichier>..." to unstage)
83-
84-
removed : .bzrignore
85-
removed : file.txt
86-
87-
----
88-
89-
This is fixed by typing:
90-
91-
[source,console]
92-
----
93-
$ git reset --hard HEAD
94-
----
95-
96-
Now let us have a look at the files to ignore.
97-
As `.bzrignore`'s format is completely compatible with `.gitignore`'s format, the simplest is to rename your `.bzrignore` file:
98-
[source,console]
99-
----
100-
$ git mv .bzrignore .gitignore
101-
----
102-
103-
Then you have to create a commit that contains this change for the migration:
104-
[source,console]
105-
----
106-
$ git commit -am 'Migration from Bazaar to Git'
107-
----
108-
109-
That's all!
110-
Now you can push the repository onto its new home server:
111-
[source,console]
112-
----
113-
$ git remote add origin git@my-git-server:mygitrepository.git
114-
$ git push origin --all
115-
$ git push origin --tags
116-
----
117-
11881
===== Case of a project with a main branch and a working branch
11982

12083
You can also import a Bazaar repository that contains branches.
12184
Let us suppose that you have two branches: one represents the main branch (myProject.trunk), the other one is the working branch (myProject.work).
85+
12286
[source,console]
12387
----
12488
$ ls
12589
myProject.trunk myProject.work
12690
----
12791

12892
Create the Git repository and `cd` into it:
93+
12994
[source,console]
13095
----
13196
$ git init git-repo
13297
$ cd git-repo
13398
----
13499

135100
Pull the master branch into git:
101+
136102
[source,console]
137103
----
138104
$ bzr fast-export --export-marks=../marks.bzr ../myProject.trunk | \
139105
git fast-import --export-marks=../marks.git
140106
----
141107

142108
Pull the working branch into Git:
109+
143110
[source,console]
144111
----
145112
$ bzr fast-export --marks=../marks.bzr --git-branch=work ../myProject.work | \
@@ -149,11 +116,38 @@ git fast-import --import-marks=../marks.git --export-marks=../marks.git
149116
Now `git branch` shows you the `master` branch as well as the `work` branch.
150117
Check the logs to make sure they’re complete and get rid of the `marks.bzr` and `marks.git` files.
151118

152-
Your working copy is still unsynchronized, so let's reset it:
119+
===== Synchronizing the staging area
120+
121+
Whatever the number of branches you had and the import method you used, your staging area is not synchronized with `HEAD`, and with the import of several branches, your working directory is not synchronized either.
122+
This situation is easily solved by the following command:
153123

154124
[source,console]
155125
----
156126
$ git reset --hard HEAD
157127
----
158128

129+
===== Ignoring the files that were ignored with .bzrignore
130+
131+
Now let's have a look at the files to ignore.
132+
As `.bzrignore`'s format is completely compatible with `.gitignore`'s format, the simplest is to rename your `.bzrignore` file.
133+
You will also have to create a commit that contains this change for the migration:
134+
135+
[source,console]
136+
----
137+
$ git mv .bzrignore .gitignore
138+
$ git commit -am 'Migration from Bazaar to Git'
139+
----
140+
141+
===== Sending your repository to the server
142+
143+
Here we are!
144+
Now you can push the repository onto its new home server:
145+
146+
[source,console]
147+
----
148+
$ git remote add origin git@my-git-server:mygitrepository.git
149+
$ git push origin --all
150+
$ git push origin --tags
151+
----
152+
159153
Your Git repository is ready to use.

0 commit comments

Comments
 (0)