2013-07-17 52 views
4

我目前正在將CVS存儲庫轉換爲多個git存儲庫。通過取消歸檔來重寫Git歷史記錄

cvs2git過程很好,但我運行filter-branch命令時遇到問題。我使用簡單的腳本測試命令,因爲主存儲庫大小爲4Go且提交超過14k次。

在此過程中,我想用git倉庫歷史記錄中的內容替換一些存檔。

下面是我用它來測試我的過濾分支--tree-filter命令腳本:

#!/bin/bash 

BASEDIR=/tmp/migration_git 
if test ! -d $BASEDIR; then 
mkdir $BASEDIR 
fi 

script_tree_filter='\ 
archives=`find . -name "archive.tgz"`; \ 
CURDIR=`pwd`; \ 
for archive in $archives; do \ 
cd `dirname $archive`; \ 
tar xzf archive.tgz ; \ 
rm -f archive.tgz ; \ 
cd $CURDIR;\ 
done' 

cd $BASEDIR 
if test -d repo.server.git; then 
    rm -rf repo.server.git; 
fi 
mkdir repo.server.git && cd repo.server.git && git init 
touch a toto && tar czf archive.tgz a && rm a && git add . && git commit -am "1st commit" && git tag commit1 
touch b a && rm archive.tgz && tar czf archive.tgz a b && rm a b && git commit -am "2nd commit" && git tag commit2 
touch a b c && rm archive.tgz && tar czf archive.tgz a b c && rm a b c && git commit -am "3rd commit" && git tag commit3 
# git rm archive.tgz && mkdir rep1 rep2 
mkdir rep1 rep2 
cd rep1 && touch a b c d && tar czf archive.tgz a b c d && rm a b c d && cd .. 
cd rep2 && touch a b c d && tar czf archive.tgz a b c d && rm a b c d && cd .. 
git add . && git commit -am "4th commit" && git tag commit4 

cd $BASEDIR 
if test -d repo.client.git; then 
    rm -rf repo.client.git; 
fi 
git clone repo.server.git repo.client.git 
cd $BASEDIR/repo.client.git 

git filter-branch -f -d /tmp/test_git --tag-name-filter cat --prune-empty --tree-filter "$script_tree_filter" -- --all 
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d 
git reflog expire --expire=now --all 
git gc --prune=now 

我有2個問題:

  1. 在結束腳本顯示錯誤在這個過程中:

    error: Untracked working tree file 'a' would be overwritten by merge.

    如果客戶克隆使用--mirror完成:

    git clone --mirror repo.server.git repo.client.git

    錯誤不會出現。我不明白爲什麼。

  2. 當我cd到repo.client.git時,存儲庫有本地修改:存檔存在,我想保留的文件是git刪除。我也不明白。 編輯:文件a,b,c,d爲空或不是不會改變結果。

+0

我無法在Ubuntu上使用git 1.8.3重現您的問題(即,我能夠無誤地運行您的腳本)。 – DomQ

+0

事實上,我正在用git 1.8.0運行這個腳本。我想他們修正了一個錯誤。感謝觀看! – Frodon

回答

0

在DomQ的評論後,我升級了我的Git版本(1.8.0 => 1.8.3),問題不再出現。

相關問題