git 支持路径中的通配符吗?
我查看、搜索和阅读文档,但找不到任何与此相关的内容。
基本上,我希望能够执行此操作:
git reset -- *.exe
或
git reset -- */some_executable.exe
代替此操作:
git reset -- some/very/long/path/some_executable.exe
另外,能够执行此操作也很好:
git reset -- topleveldirectory/another/subdirectory/*
代替此操作:
git reset -- topleveldirectory/another/subdirectory/SomeFile.cpp
git reset -- topleveldirectory/another/subdirectory/SomFile.h
我认为我可以使用通配符*
在 git-add 中添加文件,但没有找到任何适用于上述情况的内容。
有什么建议或指示我可以在哪里查找更多信息吗?
使用:64位Windows 7上的git版本1.7.3.1.msysgit.0
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 think I can use the wildcard *
in git-add to add files, but haven't found anything that works in the case above.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
Git 确实支持一些路径规范通配符,但您需要小心对字符进行 shell 转义,这样它们就不会被您的情况下的 msys bash 解释,因为 msys bash 不支持更复杂的通配符扩展。
编辑:另外,对于您的重置示例,您可以将目录作为参数传递给 git reset ,并且 git 将递归操作。
而不是
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.
EDIT: Also, for your reset example, you can just pass the directory as an argument to git reset and git will operate recursively.
rather than
要从 git 文件夹中递归重置所有 exe 文件,您可以执行以下操作:
或者,如果您想添加特定子文件夹中的所有 java 文件,您也可以这样做,如下所示:
其中 ** 表示递归所有文件夹从路径中的这一点开始
To reset all exe files recursively from within a git folder, you can do the following:
Or if you would like to add all java files within a specific sub-folder you can do that too, like this:
where ** means all folders recursively from this point in the path
然而,在某些情况下,确实需要以特定方式使用通配符来定位特定的文件子集,而不仅仅是所有文件,特别是在使用 git rm 或 git checkout 时代码>或<代码>git重置。您可以通过简单地转义通配符来实现相同的目的。
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
, orgit checkout
orgit reset
. You can achieve the same by simply escaping the wild card character.至少在子文件夹/子文件的情况下,不需要通配符。
...添加当前目录 (.) 及其下的所有内容。同样的情况...
...将添加
./files
、./files/foo.txt
和./files/foo/bar .txt
。At least in the case of subfolders/subfiles, there is no need for a wildcard.
...adds the current directory (.) and everything under it. The same goes for...
...which would add
./files
,./files/foo.txt
, and./files/foo/bar.txt
.除了已经提供的实用答案之外,这里还有关于 git pathspecs 中可以做什么和不能做什么的参考文档。通配符
*
功能在 git 术语中称为“glob magic”。https://git-scm.com/docs/gitglossary#Documentation/ gitglossary.txt-aiddefpathspecapathspec
请注意,您的 shell (bash / powershell/ …)也支持通配符。这与 git 的“glob magic”类似,但又不同。
In addition to the practical answers already provided, here are the reference docs for what you can and cannot do in git pathspecs. The wildcards
*
feature is called "glob magic", in git-terminology.https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec
Note that your shell (bash / powershell/ …) also supports globbing. This is similar to, but distinct from, git's "glob magic".
在 iTerm / zsh 中为我工作
works for me in iTerm / zsh