git 不忽略应该排除的文件
git does not ignore files that should be excluded
情况
将 gedit 3.18.3 与 Ubuntu 16.04 LTS 一起使用。
我的 .git/info/exclude 文件是
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# FILES
*.[oa]
*~
*.log
Makefile*
所以我希望匹配模式 *~
的文件被忽略。
问题
然而,这些都在计数
git status
On branch v2
Your branch is up-to-date with 'origin/v2'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
modified: README.md~
no changes added to commit (use "git add" and/or "git commit -a")
确认了此行为
git ls-files --cached --ignored --exclude-standard
如 Git: List files that should be ignored, but are not
中所建议
问题
我不希望 README.md~
或任何其他 *~
文件出现在列表中。
这曾经像 breeze 一样工作,但我无法确定出错的时刻。
请问有什么提示和解决方法吗?
自
modified: README.md
出现在您的 git status
中,我可以看到您之前已经提交了该文件。它只会被忽略,如果还没有版本化,所以你必须先删除它。
为什么要对文件进行版本控制?可能是:
- 在排除文件存在之前添加了文件(或添加了排除模式)
- 强行添加(
git add -f
)
- 其他贡献者添加了文件(请参阅下面关于
.git/info/exclude
的备注)
编辑:查看如何从版本控制中删除文件但保留本地副本的示例:
另请参阅 .gitignore
(版本化)和 .git/info/exclude
(仅限本地)之间的区别。后者不会忽略存储库其他克隆的文件:
许多人似乎对 gitignore 文件的作用有错误的认识。
它不会阻止您添加文件。
并且它不会阻止被跟踪的文件被跟踪。
它只是阻止 git 假设文件 需要 被跟踪,如果它不在索引中的话。例如,如果您从未向此 repo 添加任何内容并且您说 git add .
,则不会添加此文件。
但是一旦你添加了它,就结束了,git现在正在跟踪这个文件。它在索引中,这才是最重要的。
情况
将 gedit 3.18.3 与 Ubuntu 16.04 LTS 一起使用。
我的 .git/info/exclude 文件是
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments. # For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# FILES
*.[oa]
*~
*.log
Makefile*
所以我希望匹配模式 *~
的文件被忽略。
问题
然而,这些都在计数
git status
On branch v2
Your branch is up-to-date with 'origin/v2'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
modified: README.md~
no changes added to commit (use "git add" and/or "git commit -a")
确认了此行为
git ls-files --cached --ignored --exclude-standard
如 Git: List files that should be ignored, but are not
中所建议问题
我不希望 README.md~
或任何其他 *~
文件出现在列表中。
这曾经像 breeze 一样工作,但我无法确定出错的时刻。
请问有什么提示和解决方法吗?
自
modified: README.md
出现在您的 git status
中,我可以看到您之前已经提交了该文件。它只会被忽略,如果还没有版本化,所以你必须先删除它。
为什么要对文件进行版本控制?可能是:
- 在排除文件存在之前添加了文件(或添加了排除模式)
- 强行添加(
git add -f
) - 其他贡献者添加了文件(请参阅下面关于
.git/info/exclude
的备注)
编辑:查看如何从版本控制中删除文件但保留本地副本的示例:
另请参阅 .gitignore
(版本化)和 .git/info/exclude
(仅限本地)之间的区别。后者不会忽略存储库其他克隆的文件:
许多人似乎对 gitignore 文件的作用有错误的认识。
它不会阻止您添加文件。
并且它不会阻止被跟踪的文件被跟踪。
它只是阻止 git 假设文件 需要 被跟踪,如果它不在索引中的话。例如,如果您从未向此 repo 添加任何内容并且您说 git add .
,则不会添加此文件。
但是一旦你添加了它,就结束了,git现在正在跟踪这个文件。它在索引中,这才是最重要的。