2010-03-05 17 views
3

我使用Bazaar,我喜歡它。一般來說,我只是創建不同的分支並分別管理它們。我剛剛發現所有這些分支都可以放入存儲庫。如果我理解正確,這將節省內存並提高速度,因爲共享分支之間的一些共同祖先。問題1:我理解這個權利嗎?試圖瞭解BZR知識庫

另一件事是,當我嘗試使用它時,我發現了一些我真的不明白的問題。這是我的嘗試。

bzr init-repo --trees TestBzrRepo 
cd TestBzrRepo 
bzr init trunk 
mkdir branches 
cd branches 

bzr branch ../trunk b01-Add-file2-f 
echo 'This is file 2' > file2.f 
bzr add file2.f 
bzr commit -m "Add file 2" 

cd ../../trunk 
echo 'This is file 1' > file1.f 
bzr add file1.f 
bzr commit -m "Add file 1" 

cd ../branches/b01-Add-file2-f

從現在開始,如果我做bzr pull ../../trunk,我得到:

bzr: ERROR: These branches have diverged. Use the missing command to see how. 
Use the merge command to reconcile them.

如果我做bzr merge ../../trunk,我得到:

bzr: ERROR: Branches have no common ancestor, and no merge base revision was specified.

bzr conflicts返回任何內容,我仍然不能拉或合併。

這裏發生了什麼?接下來我該怎麼做。 請幫忙。

預先感謝您。

回答

3

是的,存儲庫允許分支機構共享共同的歷史存儲。如果你有很多有相關歷史的分支機構,這可能是一個很大的節約。

+0

感謝您澄清。 – NawaMan 2010-03-06 02:21:51

5

我認爲合併錯誤的原因是您在創建第二個分支之前未創建修訂版本。 bzr qlog TestBzrRepo可能有助於理解情況。

嘗試bzr merge ../../trunk -r 0..-1

+0

你對沒有分享修改(我簡化實驗太多)是正確的。所以現在我可以開始工作了,現在我覺得我更好了。但是,關於運行合併版本號的建議不起作用。 – NawaMan 2010-03-06 02:21:33

+1

命令應該是'bzr merge ../../trunk -r 0 ..- 1'。指定修訂版的範圍從0(歷史開始)到最新修訂版(-1)可讓您合併2個不相關的分支。 – bialix 2010-03-06 09:45:06

+0

感謝您的更正bialix。我已修復評論。 – 2010-03-08 15:51:25

5

bzr init-repo創建所謂的共享存儲庫。在共享存儲庫中,所有修訂都存儲在存儲庫的.bzr目錄中,而分支的.bzr目錄本身僅存儲分支元信息,而不是存儲修訂本身。這樣分支目錄變得非常輕量級,並且分支的常見修訂不會被重複。

比方說,我們創建了一個共享的存儲庫和樹枝裏面是這樣的:

bzr init-repo the-project  # create shared repo 
bzr init the-project/trunk # create a branch inside shared repo 
cd the-project/trunk   # cd to branch dir 
cp -r /path/to/files/* .  # copy the project's files into the branch 
bzr add      # tell bazaar to add everything to version control 
bzr commit -m 'added files' # commit the changes (add files) 
bzr branch . ../branch1  # create another branch from the current one 
bzr branch . ../branch2  # create another branch from the current one 

然後佈局的目錄將會像這樣:

the-project/.bzr   -- only revisions are stored here, no branch info 
the-project/trunk/.bzr -- only branch info is stored here, no revisions 
the-project/branch1/.bzr -- only branch info is stored here, no revisions 
the-project/branch2/.bzr -- only branch info is stored here, no revisions 

如果您使用不共享倉庫的情況會有很大的不同,例如:

bzr init trunk # create a branch inside shared repo 
cd the-project-trunk   # cd to branch dir 
cp -r /path/to/files/* .  # copy the project's files into the branch 
bzr add      # tell bazaar to add everything to version control 
bzr commit -m 'added files' # commit the changes (add files) 
bzr branch . ../branch1  # create another branch from the current one 
bzr branch . ../branch2  # create another branch from the current one 

在th是的情況下(沒有共享回購)佈局的目錄將起作用這樣的:

trunk/.bzr -- revisions + branch info are stored here 
branch1/.bzr -- revisions + branch info are stored here 
branch2/.bzr -- revisions + branch info are stored here 

在這種情況下的修改將在所有3個分支被複制。

bzr pull如果當前分支是其他分支後面的一些修訂版本,這樣可以直接附加缺少的修訂版本,這很有用。如果當前分支有一些修改,而另一個則沒有,那麼拉失敗,如你的例子。這是非常正常的,在這種情況下的解決方案是與bzr merge進行正常合併。

bzr merge在您的示例中失敗,因爲兩個分支(trunk和其他分支)沒有共同的修訂。這是因爲當你從樹幹分支時,它完全是空的,沒有修改它。這兩個分公司是完全獨立的,絕對沒有共同的修改。

仍然可以將不相關的分支作爲@bialix與bzr merge ../../trunk -r0..-1進行解釋,但我不認爲這是您的意圖。從一個沒有修訂的主幹分支是毫無意義的,在一個實際的用例中,您將從一個至少有一個修訂的分支中分支,在這種情況下,您不會得到這樣的錯誤,並且合併將按預期工作。