.gitignore 排除所有目录中的文件
.gitignore excluding files in all directories
在.git忽略我有
phpmyadmin
.idea
config.php
admin/config.php
system/cache/*
system/logs/*
image/cache/*
git 以某种方式忽略了 system/library/config.php
中的 config.php
文件,为什么会发生这种情况?以及如何避免这种情况?
您可以尝试从该路径的git忽略规则中排除该文件:
config.php
!system/library/config.php
在 gitignore
查看更多信息:
[The] prefix "!
" negates the pattern; any matching file excluded by a previous pattern will become included again.
It is not possible to re-include a file if a parent directory of that file is excluded
请注意,对于 git 2.9.x/2.10(2016 年年中?),如果文件的父目录被排除在外,则可能会重新包含该文件 if there is no wildcard in the path re-included.
Nguyễn Thái Ngọc Duy (pclouds
) 正在尝试添加此功能:
- commit 506d8f1 for git v2.7.0, reverted in commit 76b620d git v2.8.0-rc0
- commit 5e57f9c git v2.8.0-rc0,... reverted(!) in commit 5cee3493 git 2.8.0-rc4.
按照@VonC 的建议添加 !system/library/config.php 应该可行。
至于为什么它首先被忽略,请尝试查看您的全局 gitignore
规则或文件。可能有旧项目的剩余物。
如果您包含一个不包含 /
的文件名(或 glob),Git 将忽略与目录树中任何位置匹配的文件。
如果只想忽略顶级目录中的config.php,可以添加一个前导斜杠以确保它只在顶级目录中匹配:
/config.php
如 .gitignore
documentation (man gitignore
) 所述:
- 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. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
- A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
在.git忽略我有
phpmyadmin
.idea
config.php
admin/config.php
system/cache/*
system/logs/*
image/cache/*
git 以某种方式忽略了 system/library/config.php
中的 config.php
文件,为什么会发生这种情况?以及如何避免这种情况?
您可以尝试从该路径的git忽略规则中排除该文件:
config.php
!system/library/config.php
在 gitignore
查看更多信息:
[The] prefix "
!
" negates the pattern; any matching file excluded by a previous pattern will become included again.
It is not possible to re-include a file if a parent directory of that file is excluded
请注意,对于 git 2.9.x/2.10(2016 年年中?),如果文件的父目录被排除在外,则可能会重新包含该文件 if there is no wildcard in the path re-included.
Nguyễn Thái Ngọc Duy (pclouds
) 正在尝试添加此功能:
- commit 506d8f1 for git v2.7.0, reverted in commit 76b620d git v2.8.0-rc0
- commit 5e57f9c git v2.8.0-rc0,... reverted(!) in commit 5cee3493 git 2.8.0-rc4.
按照@VonC 的建议添加 !system/library/config.php 应该可行。 至于为什么它首先被忽略,请尝试查看您的全局 gitignore 规则或文件。可能有旧项目的剩余物。
如果您包含一个不包含 /
的文件名(或 glob),Git 将忽略与目录树中任何位置匹配的文件。
如果只想忽略顶级目录中的config.php,可以添加一个前导斜杠以确保它只在顶级目录中匹配:
/config.php
如 .gitignore
documentation (man gitignore
) 所述:
- 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. For example, "Documentation/*.html" matches "Documentation/git.html" but not "Documentation/ppc/ppc.html" or "tools/perf/Documentation/perf.html".
- A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".