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.
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).
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