英文:
Extract a given set of files to a repository
问题
I intend to extract a handful of files from a repository with ~10000 commits and 5000 files into a separate repository. Those files are spread across several directories, and there are unrelated files in those directories.
git filter-branch
's --subdirectory-filter
is not really an option, since it only accepts a single directory. Also, it doesn't follow renames, so part of the history, if the file was initially introduced in another directory, is lost.
My current solution is:
git filter-branch --tree-filter 'fd -E 3166 -X rm -rf';
Where fd
is a faster find
, and 3166
is a unique part of the file name of all extracted files. What it does it goes through all the commits, find all unrelated files and removes them. This is horribly slow, however, it takes hours.
Is there a better approach?
英文:
I intend to extract a handful of files from a repository with ~10000 commits and 5000 files into a separate repository. Those files are spread across several directories, and there are unrelated files in those directories.
git filter-branch
's --subdirectory-filter
is not really an option, since it only accepts a single directory. Also, it doesn't follow renames, so part of the history, if the file was initially introduced in another directory, is lost.
My current solution is:
git filter-branch --tree-filter 'fd -E 3166 -X rm -rf'
Where fd
is a faster find
, and 3166
is a unique part of the file name of all extracted files. What it does it goes through all the commits, find all unrelated files and removes them. This is horribly slow, however, it takes hours.
Is there a better approach?
答案1
得分: 4
我猜你可以测试filter-repo
(这是由Git官方推荐使用的替代filter-branch
的工具)。在那里,你可以指定多个文件夹....我猜你可以提供所有你关心的目录,无论是"current"还是你以前拥有的。
https://github.com/newren/git-filter-repo
英文:
I guess you could test filter-repo
(which is being recommended by git upstream to use instead of filter-branch). There you could specify more than one folder.... I guess you could provide all the directories that you care, both "current" and as you had them historically.
答案2
得分: 2
git filter-branch
还具有 --index-filter
模式。
正如文档所述:
这是用于重写索引的过滤器。它类似于树过滤器,但不会检出树,这使它运行速度更快。
正如文档仍然指出的:你可能希望与 git rm --cached [不符合你的过滤器的所有文件]
一起使用它。
英文:
git filter-branch
also has an --index-filter
mode.
As the documentation states :
> This is the filter for rewriting the index. It is similar to the tree filter but does not check out the tree, which makes it much faster.
As the documentation still states : you porbably want to use it together with git rm --cached [all the files that don't match your filter]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论