git - 通过 untaring archives 重写 Git 历史

标签 git git-filter-branch

我目前正在将 CVS 存储库转换为多个 git 存储库。

cvs2git 进程很好,但是我在运行 filter-branch 命令时遇到了问题。我使用简单的脚本测试命令,因为主存储库大小为 4Go,提交次数超过 14k。

在此过程中,我想用 git repo 历史记录中的内容替换一些文件。

这是我用来测试我的 filter-branch --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

我有两个问题:

  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 是否为空都不会改变结果。

最佳答案

根据 DomQ 的评论,我升级了我的 Git 版本(1.8.0 => 1.8.3),问题不再出现。

关于git - 通过 untaring archives 重写 Git 历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17704482/

相关文章:

windows - 终端上的 git status 暂停列表

git - 我如何 git squash 更早地一起提交?

git - 在工作树层次结构中向上移动 .git 文件夹

git 按子文件夹拆分存储库并保留所有旧分支

Git:从历史记录中删除文件夹,除了一位作者

git:如何从项目中分离出库?过滤器分支,子树?

git 根分支...它们是如何工作的?

推送到github后Android项目jar文件丢失

git - 进行更改后 fork Git 存储库

git - 拆分巨大的 git 仓库