git只检出整个项目的某些文件类型 [英] git checkout only certain file types for entire project

查看:84
本文介绍了git只检出整个项目的某些文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以仅对某些文件类型(.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-treegrep尝试类似的操作:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆