git只检出整个项目的某些文件类型 [英] git checkout only certain file types for entire project
问题描述
有没有一种方法可以仅对某些文件类型(.xlf)执行git checkout,而该文件类型又会遍历整个存储库?结果应包含存储库的结构,即文件夹以及特定扩展名的包含文件.
Is there a way to perform a git checkout for only certain file types (.xlf), which recurses down through the entire repository? The results should contain the struture of the repository, meaning the folders, and the contained files of a certain extension.
回购A
file.xlf
file.txt
level2/
file2.xlf
file2.txt
level3/
file3.xlf
file3.txt
结帐后,回购B如下:
回购B
file.xlf
/level2
file2.xlf
/level3
file3.xlf
这是我到目前为止所拥有的:
This is what I have so far:
$ git checkout FETCH_HEAD -- '*.xlf'
这会在根级别提供所有".xlf"
文件,但不会递归到子目录.
This gives all of the ".xlf"
files at the root level, but is not recursive down to subdirectories.
谢谢您的帮助.
推荐答案
UPDATE: Check Dadaso's answer for a solution that will work in most of cases.
您可以使用git ls-tree
和grep
尝试类似的操作:
You can try something like this, using git ls-tree
and grep
:
git checkout origin/master -- `git ls-tree origin/master -r --name-only | grep ".xlf"`
请注意,这需要master
分支中的远程origin
.另外,您必须为grep
提供正确的过滤器/扩展名.
Note this expects a remote origin
in a master
branch. Also you must provide the right filter/extension to grep
.
在执行此命令之前,您应该执行以下操作:
Before this command, you should have done something like this:
git init
git remote add origin <project.git>
git fetch
这篇关于git只检出整个项目的某些文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!