使用特定的文件名检出先前提交的所有文件 [英] Checkout all files from a previous commit with a certain file name
问题描述
我想用特定文件名签出所有文件。它们的路径如下所示:Assets / stickers / * / icon.png其中*是一堆不同的目录(即其中一个文件是Assets / stickers / a / icon.png另一个是Assets / stickers / b / icon .PNG)。我怎样才能编写一个命令来从旧的提交中提取这个名字的所有文件?我尝试了下面的命令,但没有收到错误,但是这些文件没有被签出:
I want to checkout all files with a certain file name. The path to them looks like this: Assets/stickers/*/icon.png where * is a bunch of different directories (i.e. one of the files is Assets/stickers/a/icon.png another is Assets/stickers/b/icon.png). How can I write a command that will pull all the files with that name from an old commit? I tried the following command and didn't get an error, but the files were not checked out:
git checkout aa47381b99a38c0cabef28bb54f7a7f119b36797 Assets/stickers/*/icon.png
推荐答案
我的资料库中的命令引用了手册,但没有人工作:
I tried the following commands in my repo referring to the manual but no one worked:
git checkout <commit> dir/*/foo.txt
git checkout <commit> dir/**/foo.txt
git checkout <commit> ':(glob)dir/*/foo.txt'
git checkout <commit> ':(glob)dir/**/foo.txt'
git checkout <commit> ':(glob)**/foo.txt'
也许是pathspec的一个bug。
作为一种解决方法,这可能适用:
Maybe a bug of pathspec. As a workaround, this probably works:
git ls-tree --name-only -r aa47381b99a38c0cabef28bb54f7a7f119b36797 Assets/stickers/ | grep icon.png | xargs git checkout aa47381b99a38c0cabef28bb54f7a7f119b36797
这篇关于使用特定的文件名检出先前提交的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!