git 支持路径中的通配符吗?

发布于 2024-10-17 17:47:43 字数 696 浏览 2 评论 0原文

我查看、搜索和阅读文档,但找不到任何与此相关的内容。

基本上,我希望能够执行此操作:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

随梦而飞# 2024-10-24 17:47:43

Git 确实支持一些路径规范通配符,但您需要小心对字符进行 shell 转义,这样它们就不会被您的情况下的 msys bash 解释,因为 msys bash 不支持更复杂的通配符扩展。

编辑:另外,对于您的重置示例,您可以将目录作为参数传递给 git reset ,并且 git 将递归操作。

git reset my/long/path

而不是

git reset my/long/path/*

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.

git reset my/long/path

rather than

git reset my/long/path/*
新人笑 2024-10-24 17:47:43

要从 git 文件夹中递归重置所有 exe 文件,您可以执行以下操作:

git reset -- \*.exe

或者,如果您想添加特定子文件夹中的所有 java 文件,您也可以这样做,如下所示:

git add ./some/sub/folder/path/**/*.java

其中 ** 表示递归所有文件夹从路径中的这一点开始

To reset all exe files recursively from within a git folder, you can do the following:

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:

git add ./some/sub/folder/path/**/*.java

where ** means all folders recursively from this point in the path

画尸师 2024-10-24 17:47:43

然而,在某些情况下,确实需要以特定方式使用通配符来定位特定的文件子集,而不仅仅是所有文件,特别是在使用 git rm 或 git checkout 时代码>或<代码>git重置。您可以通过简单地转义通配符来实现相同的目的。

git rm app/assets/javascript/templates/projects/\*.jst.ejs

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 app/assets/javascript/templates/projects/\*.jst.ejs
香橙ぽ 2024-10-24 17:47:43

至少在子文件夹/子文件的情况下,不需要通配符。

git add .

...添加当前目录 (.) 及其下的所有内容。同样的情况...

git add files/

...将添加 ./files./files/foo.txt./files/foo/bar .txt

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.

扎心 2024-10-24 17:47:43

除了已经提供的实用答案之外,这里还有关于 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".

世界和平 2024-10-24 17:47:43
git diff '*word*'

在 iTerm / zsh 中为我工作

git diff '*word*'

works for me in iTerm / zsh

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文