如何使用通配符路径规范从分支中检出文件? [英] How to checkout files from branch with wildcard path spec?

查看:83
本文介绍了如何使用通配符路径规范从分支中检出文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用通配符检出文件,如 git-scm页面上所述,来自特定的refspec.举例说明问题.

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.

使用Java和C文件创建存储库:

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

删除Java文件:

$ 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

尝试从上一次提交中检出已删除的Java文件:

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.

推荐答案

据我所知,当您执行git checkout d62e124f -- '*.java'时,git使用当前工作树来扩展*.java d62e124f.由于您刚刚删除了所有文件,因此没有任何匹配.

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.

git restore --source d62e124f '*.java'

有效,因为git然后使用正确的ref来扩展通配符.

works, as git then uses the correct ref to expand the wildcard.

git restore仅从2.23.0开始可用,然后才能使用:

git restore is only available since 2.23.0, before that you can use:

git ls-files d62e124f '*.java' | xargs git checkout d62e124f

这篇关于如何使用通配符路径规范从分支中检出文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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