Reputation: 2418
I'm unable to checkout files using wildcards, as described on the git-scm page, from a specific refspec . Describing the issue with an example.
Creating a repository with java and c files:
$ git log --pretty=oneline
d62e124f02e9ec6e2848ccc8db05bb37db167281 All files
$ git ls-tree -r --name-only HEAD .
c/one/first.c
c/two/second.c
java/one/first.java
java/two/second.java
Removing the java files:
$ git log --pretty=oneline
97b2ffbdd79f924ca27d0404c612b93feee7f492 Removed java files
d62e124f02e9ec6e2848ccc8db05bb37db167281 All files
$ git ls-tree -r --name-only HEAD .
c/one/first.c
c/two/second.c
Trying to checkout the deleted java files, from the previous commit:
$ git checkout d62e124f -- '*.java'
error: pathspec '*.java' did not match any file(s) known to git.
Upvotes: 0
Views: 1265
Reputation: 7380
As far as I can tell, when you do git checkout d62e124f -- '*.java'
, git uses the current working tree to expand *.java
, not d62e124f
. As you have just deleted all the files, it matches nothing.
Doing
git restore --source d62e124f '*.java'
works, as git then uses the correct ref to expand the wildcard.
git restore
is only available since 2.23.0, before that you can use:
git ls-files d62e124f '*.java' | xargs git checkout d62e124f
Upvotes: 1