2010-08-27 42 views
8

如何更改r0,使其看起來像我在創建我的存儲庫時添加.hgignore或在我的當前r0之前插入提交?如何插入或更改mercurial修訂版

我剛剛使用hgsvn將一個巨大的SVN回購轉換爲mercurial。它花了幾個小時,不得不通過大約十幾個分支來獲得整個事情。我現在的問題是.hgignore沒有提交,所以當我hgimportsvn一個分支時,.hgignore似乎並沒有提供。我想插入該文件作爲r0的一部分,或者在此之前插入它(並將所有內容都移除1)。我也嘗試在我的Mercurial幹線結帳時提交它,但似乎總是克隆(分支?)從同樣的Mercurial修訂我的SVN分支創建的,因此.hgignore再次丟失。

+0

hg history被設計爲不可變的。但是,最好的辦法是(1)重新導入整個文件,但在導入之前添加文件或(2)做一些hg隊列跳舞。 – 2010-08-27 23:13:28

回答

5

您可能需要類似ConvertExtension之類的東西。查看--splicemap選項。

要創建一個新的歷史添加了作爲第一個版本A .hgignore文件:

  1. 創建一個新的存儲庫,其唯一的修訂是.hgignore提交。
  2. 創建一個包含兩個40字符散列的splicemap文件:當前數據庫的rev 0和新數據庫的rev 0。
  3. 運行hg convert <current_db_dir> <new_db_dir> --splicemap splice_filename

這增加了每個版本在當前數據庫到新的數據庫。 splicemap指定父項的編輯,所以如果當前數據庫的版本0將其父集設置爲新數據庫的版本0。

下面是一個Windows批處理文件,它創建一個3修訂版數據庫和1修訂版數據庫,其中包含.hgignore文件,將它們拼接在一起。結果應該是你在找什麼。如果您的原始數據庫較大,則可能需要一段時間,因爲源數據庫的整個歷史記錄都會重新寫入目標數據庫。

@echo off 

@REM Create a 3-revision database 
hg init current 
cd current 
echo >file1 
hg add 
hg ci -m file1 
echo >file2 
hg add 
hg ci -m file2 
echo >file3 
hg add 
hg ci -m file3 

@REM Add the first revision to the splice map 
hg log -r 0 --template "{node} " > ..\map 

@REM Display the result 
hg log 
cd .. 

@REM Create a 1-revision database 
hg init ignore 
cd ignore 
echo glob:*.txt>.hgignore 
hg add 
hg ci -m ignore 

@REM Specify this node as the parent of the other 
@REM database's first revision in the splice map 
hg log -r 0 --template "{node}\n" >> ..\map 
hg log 
cd .. 

@REM Here's the resulting splice map 
type map 

@REM Make a copy to store the result 
hg clone ignore result 

@REM Add revisions from "current" to "result" honoring 
@REM the splice map 
hg convert current result --splicemap map 

@REM Display the result 
cd result 
hg log 
+0

我正在使用hgsvn,因爲我無法使ConvertExtension做我想要的。雖然拼接可能是正確的解決方案,但我不明白如何在我的情況下使用它。 – 2010-09-01 16:07:57

+0

@Asa,我用一個使用'hg convert'的例子更新了我的答案。我希望有所幫助。 – 2010-09-02 02:54:05

+0

Brillant anwer,謝謝! – CharlesB 2017-01-18 09:37:02

相關問題