git - 从 git svn clone 中排除文件

标签 git git-svn

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

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

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

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

最佳答案

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

我相信仅将文件放入 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 pull 到其他地方,那么它会更简单,因为它是你应用于原始 repo 的一次性修复而不是为每个单独的克隆做一些事情。

关于git - 从 git svn clone 中排除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34879226/

相关文章:

git - 为什么 git svn show-ignore/show-externals 这么慢?

github "origin"删除

android - shell脚本envsetup.sh是如何执行launch的?

git - Atlassian Stash 表示第二个 pull 请求已远程 merge

php - 动态包含在 composer.json 中的克隆项目

svn - 将现有的 svn 项目导入 github 存储库

git - 使用 no-ff merge IntelliJ 任务

git svn 需要很长时间

git - 如何克隆本地 svn 存储库?

git-svn 克隆失败,perl.exe 断言失败