Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout from a commit all files that end with a specific extension

Tags:

git

I know how to checkout one file from a commit.

git checkout a0b1c3d -- path/to/some/file.txt

I also know how to checkout multiple files from a commit.

git checkout a0b1c3d -- path/to/some/file.txt path/to/another/file.txt

How can we checkout all the files that end with a certain extension? I have tried the following:

git checkout a0b1c3d -- *.txt
git checkout a0b1c3d -- */**/*.txt

Neither work. Both commands checkout nothing, even though there are *.txt files to checkout from the specified commit.

Checkout all files from a previous commit with a certain file name suggests that there might be a bug in pathspec.

like image 551
Shaun Luttin Avatar asked Oct 28 '25 15:10

Shaun Luttin


1 Answers

Quote the glob so your shell passes it along to Git rather than expanding it itself:

git checkout -- \*.txt

which just worked perfectly for me, it checked out all .txt files (at any level, see git's rules for pathname matching on the command line, git help glossary and find pathspec).

like image 112
jthill Avatar answered Oct 31 '25 06:10

jthill