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.
Repo A
file.xlf
file.txt
level2/
file2.xlf
file2.txt
level3/
file3.xlf
file3.txt
After checkout repo B looks like:
Repo B
file.xlf
/level2
file2.xlf
/level3
file3.xlf
This is what I have so far:
$ git checkout FETCH_HEAD -- '*.xlf'
This gives all of the ".xlf"
files at the root level, but is not recursive down to subdirectories.
Thank you for the help.
While getting error “did not match any file s known to git”, You can try git fetch so that your local repository gets all the new info from github. It just takes the information about new branches and no actual code. After that, the git checkout should work fine.
In git you can define "filters" that affect the process of moving files from the index to the work tree ("smudge" filters) and from the work tree to the index ("clean" filters). Typically you'll find a . gitattribute file that associates the filters with files at specific paths.
Partial clone is a performance optimization that “allows Git to function without having a complete copy of the repository. The goal of this work is to allow Git better handle extremely large repositories.” Git 2.22. 0 or later is required.
You don't need find or sed, you can use wildcards as git understands them (doesn't depend on your shell):
git checkout -- "*.xml"
The quotes will prevent your shell to expand the command to only files in the current directory before its execution.
You can also disable shell glob expansion (with bash) :
set -f
git checkout -- *.xml
This, of course, will irremediably erase your changes!
UPDATE: Check Dadaso's answer for a solution that will work in most of cases.
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"`
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With