git 是否支持路径中的通配符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5012086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does git support wildcards in paths?
提问by Nathan McDaniel
I have looked, searched, and read documentation and can't really find anything about this.
我已经查看、搜索并阅读了文档,但实际上找不到任何关于此的信息。
Basically, I want to be able to do this:
基本上,我希望能够做到这一点:
git reset -- *.exe
or
或者
git reset -- */some_executable.exe
Instead of this:
取而代之的是:
git reset -- some/very/long/path/some_executable.exe
Also it'd be nice to be able to do this:
能够做到这一点也很好:
git reset -- topleveldirectory/another/subdirectory/*
Instead of this:
取而代之的是:
git reset -- topleveldirectory/another/subdirectory/SomeFile.cpp
git reset -- topleveldirectory/another/subdirectory/SomFile.h
I thinkI can use the wildcard *
in git-add to add files, but haven't found anything that works in the case above.
我想我可以*
在 git-add 中使用通配符来添加文件,但没有找到任何适用于上述情况的内容。
Any suggestions or pointers to where I can look for more info?
任何建议或指示我可以在哪里查找更多信息?
Using: git version 1.7.3.1.msysgit.0 on 64-bit Windows 7
使用:64 位 Windows 7 上的 git 版本 1.7.3.1.msysgit.0
采纳答案by Matt Enright
Git does support some pathspec globbing, but you need to be careful to shell-escape the characters so they aren't interpreted by in your case, msys bash, which doesn't support more sophisticated wildcard expansion.
Git 确实支持一些 pathspec globbing,但是您需要小心对字符进行 shell 转义,以便在您的情况下不会解释它们,msys bash,它不支持更复杂的通配符扩展。
EDIT: Also, for your reset example, you can just pass the directory as an argument to git reset and git will operate recursively.
编辑:另外,对于您的重置示例,您可以将目录作为参数传递给 git reset 并且 git 将递归运行。
git reset my/long/path
rather than
而不是
git reset my/long/path/*
回答by Dhruva Sagar
In some cases however, one does need to use wildcards in a specific way to target a specific subset of files and not just all files, especially when working with git rm
, or git checkout
or git reset
. You can achieve the same by simply escaping the wild card character.
但是,在某些情况下,确实需要以特定方式使用通配符来定位特定的文件子集,而不仅仅是所有文件,尤其是在使用git rm
,git checkout
或 时git reset
。您可以通过简单地转义通配符来实现相同的目的。
git rm app/assets/javascript/templates/projects/\*.jst.ejs
回答by Lars Juel Jensen
To reset all exe files recursively from within a git folder, you can do the following:
要从 git 文件夹中递归重置所有 exe 文件,您可以执行以下操作:
git reset -- \*.exe
Or if you would like to add all java files within a specific sub-folder you can do that too, like this:
或者,如果您想在特定子文件夹中添加所有 java 文件,您也可以这样做,如下所示:
git add ./some/sub/folder/path/**/*.java
where ** means all folders recursively from this point in the path
其中 ** 表示所有文件夹从路径中的这一点递归
回答by coreyward
At least in the case of subfolders/subfiles, there is no need for a wildcard.
至少在子文件夹/子文件的情况下,不需要通配符。
git add .
...adds the current directory (.) and everything under it. The same goes for...
...添加当前目录 (.) 及其下的所有内容。这同样适用于...
git add files/
...which would add ./files
, ./files/foo.txt
, and ./files/foo/bar.txt
.
...这将添加./files
, ./files/foo.txt
, 和./files/foo/bar.txt
。