简体   繁体   English

Git:如何检出特定目录中的所有已提交的.css文件?

[英]Git: How to checkout all committed .css files in specific directory?

I added and deleted a bunch of files in /webroot/modules/mod_menu and I want to get all my .css files back from my last commit. 我在/webroot/modules/mod_menu添加和删​​除了一堆文件,我想从上一次提交中获取所有的.css文件。 Unfortunately, I've deleted them and I don't remember their names. 不幸的是,我删除了它们,我不记得他们的名字了。

If I try to do 如果我尝试去做

git checkout HEAD^ /webroot/modules/mod_menu/*.css

it fails with a message like 它失败并显示一条消息

error: pathspec '/webroot/modules/mod_menu/css_5XB5aQOGzDUVxnwtHDXg0AJDjmjZbe2Sh1K2BEkR5cM.css' did not match any file(s) known to git.
error: pathspec '/webroot/modules/mod_menu/css_foYlSNpOa-3y78f5xFwefA_kiFD67qfm6I1kXpro1XI.css' did not match any file(s) known to git.
error: pathspec '/webroot/modules/mod_menu/css_n7aK8s-ciXhQyEYWNOJtISbWxtxQiQvnD-N_xWUtD5A.css' did not match any file(s) known to git.

That makes sense: the files it is trying to checkout are new ones, not the files that were in my previous commit. 这是有道理的:它正在尝试检出的文件是新文件,而不是我先前提交中的文件。 But if I don't know the names of the files, how do I check them out? 但是,如果我不知道文件名,该如何检出它们?

The documentation for checkout has this in the SYNOPSIS section 对于文档检出有这样的概要部分

git checkout [-p|--patch] [<tree-ish>] [--] [<paths>…]

Looks like you're missing the -- between <tree-ish> and <paths> . 似乎您缺少了<tree-ish><paths>之间的-- The following should work. 以下应该工作。

git checkout HEAD^ -- /webroot/modules/mod_menu/*.css

what is that -- ? 那是什么 - ? ... ...

According to this answer The double-dash is used to separate references, such as master or HEAD from file paths... 根据此答案 ,双破折号用于将引用(例如master文件或HEAD与文件路径分开...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM