从 git svn clone 中排除文件

Exclude files from git svn clone

我正在将一个 SVN 存储库迁移到 Git,我有 7000 多个二进制文件,我想从一开始就排除在导入之外并成为 Git 历史的一部分,相反之后清理它们(参考此 )。文件的位置不遵循非常规则的模式,因此我必须向 git 提供相当长的位置列表,并且我要考虑约 8000 次提交。

如果我的目标是避免使用不必要的文件使存储库膨胀,那么最好的方法是什么?

有没有一种方法可以从一开始就排除这些,也许作为 git svn clone 的标志?在克隆之前将它们添加到 .gitignore 会阻止它们被添加吗?

另一种选择是全部导入,然后使用 git filter-branch 重写整个历史记录以在与其他人共享存储库之前删除所有这些文件。

根据你的问题和评论,我认为没有一种方法可以在没有你不想要的某些文件的情况下简单地克隆。

我认为仅将文件放入 gitingore 文件不会对您对存储库所做的 git 克隆产生任何影响。

但是,在服务器上您可以创建一个没有这些文件的过滤分支,您可以从中提取这些文件,正如 this 问题建议的答案之一针对他们的类似问题所建议的那样:

On the server:

git checkout master^0    # the ^0 checks out the commit itself, not the branch
git filter-branch --tree-filter 'git rm -r wp-content/uploads' HEAD
git checkout -b filtered

(filter-branch on a big project here generates new history at about 2-3 commits per second)

Then, anywhere you like,

git init
git remote add gimme your://repo/path
git fetch gimme filtered

正如 documentation 所说,filter-branch 命令对以下情况很有用,它似乎很好地包含了您所处的情况:

Those filters can modify each tree (e.g. removing a file or running a perl rewrite on all files) or information about each commit. Otherwise, all information (including original commit times or merge information) will be preserved.


编辑:这有额外的好处,如果你想在未来从这个 repo 拉到其他地方,那么它就简单多了,因为它是你一次性修复的适用于原始回购,而不是为每个单独的克隆所做的事情。