将 SVN 迁移到 Git 并过滤历史记录

Migrate SVN to Git with filtered history

我想将项目从 SVN 迁移到 Git 并保留历史记录。

但是因为SVN仓库中有一些带有生产密码的配置文件和其他敏感数据,我想从迁移历史中排除这几个文件。

我该怎么做?

基本上你有两种策略

  1. 先清理SVN再迁移到GIT
  2. 先迁移然后在GIT
  3. 中清理

先清理SVN再迁移到GIT

根据SVN:

"(...)您唯一的办法是 svnadmin 转储您的存储库,然后通过 svndumpfilter(不包括错误路径)将转储文件通过管道传输到 svnadmin 加载命令(...)" =38=]

http://subversion.apache.org/faq.html#removal

先迁移然后在GIT

中清理

Github 有一篇关于此的好文章

https://help.github.com/articles/remove-sensitive-data/

最简单的解决方案是 migrate your SVN repository to Git on your local machine and then remove the files that contain the sensitive data 在将迁移的历史记录推送到远程存储库之前

例如:

# Migrate the SVN project into a local repo
git svn clone svn://server/svnroot \
    --authors-file=authors.txt \
    --no-metadata \
    -s your_project

cd your_project   

# Remove the 'passwd.txt' file from the history of the local repo
git filter-branch --force --index-filter \
    'git rm --cached --ignore-unmatch passwd.txt' \
    --prune-empty --tag-name-filter cat -- --all

只要您不将本地 Git 存储库推送到远程位置,您就可以使用 git filter-branch 安全地从整个历史记录中删除任何文件。删除文件后,可以安全地将存储库发布到任何你想要的地方。

git filter-branch 的另一种解决方案是使用名为 BFG Repo-Cleaner, which uses its own -supposedly faster- implementation to remove a file from the history of a Git repository. With 的工具,它可能值得考虑,因为 git filter-branch 的性能至少会达到 linear 到要处理的提交数。