gpt4 book ai didi

git - .gitignore 不会忽略子目录中的文件

转载 作者:太空狗 更新时间:2023-10-29 13:31:16 26 4
gpt4 key购买 nike

我的存储库顶级文件夹中有一个 .gitignore 文件,其中包含以下代码:

# Compiled python modules.
*.pyc

# Backup gedit files.
/*~

# Setuptools distribution folder.
/dist/

# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info
/*.egg

当我尝试运行 git add . 命令时,.gitignore 没有任何效果,因为添加了几个/*~。 git status 的输出如下:

new file:   uvispace/tests/test_messenger.py
new file: uvispace/tests/test_messenger.py~
new file: uvispace/tests/test_robot.py~
new file: uvispace/uvirobot/__main__.py~
new file: uvispace/uvirobot/messenger.py~
new file: uvispace/uvirobot/move_base.py

类似问题

我见过几个非常相似的问题,比如 this one , 或 this one .他们的解决方案是删除以前添加的文件,然后按照以下说明再次添加整个存储库:

git rm -rf --cached .
git add *

不过我试了一下,没有区别。任何人都知道为什么会发生这种情况?

最佳答案

关于 gitignore-syntax 的文档可以在这里找到:git-scm.com/docs/gitignore

一件事可能是错误的是你的 /*~ 因为单个 * 不起作用你期望的方式:

For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".

您必须改用 **:

•A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

•A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.

•A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.

关于git - .gitignore 不会忽略子目录中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40174247/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com