为什么gitignore在这种情况下工作?

编程入门 行业动态 更新时间:2024-10-25 15:23:55
本文介绍了为什么gitignore在这种情况下工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个我希望忽略的文件:

  • .idea / workspace.xml
  • someapp / src / .idea / workspace.xml

我认为将这一规则添加到.gitignore就足够了:

.idea / workspace.xml

但它仅捕获顶级.idea / workspace.xml(git status显示someapp / src / .idea / workspace.xml为未跟踪)。

<我也尝试过 ** /。idea / workspace.xml ,但是这根本不起作用。帮助?

解决方案

  • [...] $ b
  • 如果模式不包含斜杠/,git会将其视为shell glob模式,并检查与路径名相对于.gitignore文件位置的匹配(相对于工作树的顶层if而不是来自.gitignore文件)。
  • 否则,git会将该模式视为适合fnmatch(3)与FNM_PATHNAME标志使用的shell glob:模式中的通配符不会与路径名中的/匹配。 [b]

只要路径包含斜线,Git就不会再检查匹配的路径,而是直接使用glob行为。因此,您无法匹配 .idea / workspace.xml ,但仅适用于 workspace.xml 。

Git手册:gitignore 。

I have two files I wish to ignore:

  • .idea/workspace.xml
  • someapp/src/.idea/workspace.xml

I thought adding this single rule to .gitignore will suffice:

.idea/workspace.xml

But it only catches the top-level .idea/workspace.xml (git status shows someapp/src/.idea/workspace.xml as untracked).

I also tried **/.idea/workspace.xml, but this doesn't work at all. Help?

解决方案

  • […]
  • If the pattern does not contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).
  • Otherwise, git treats the pattern as a shell glob suitable for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards in the pattern will not match a / in the pathname. […]

As soon as the path contains a slash, Git will no longer check for a match in the path but instead will use the glob behaviour directly. As such, you cannot match for .idea/workspace.xml but only for workspace.xml.

Git manual: gitignore.

更多推荐

为什么gitignore在这种情况下工作?

本文发布于:2023-10-27 22:43:47,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在这种情况下   工作   gitignore

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!