git - .gitignore of the parent module affects add and commit of the child module
问题描述
In my home directory, I have a git repository to track configuration files, such as .zshrc, .vimrc. The .gitignore file excludes all the files except these specified ones.
In my ~/Desktop/ directory, I have cloned one other project, and it has its own .gitignore. However, when I created new files in this child module and try to add and commit them. It always says "nothing to commit, working tree clean"
I try to delete the .gitignore of the parent module, and the child module can add and commit. This means "git add" of my child module is affected by the parent module's .gitignore. I also tried created dummy nested repositories, the .gitignore from parent did not affect its child repository. Now I am confused with this different behaviour.
This is parent's .gitignore
# Ignore everything
*
# But not these files:
!.gitignore
!.zshrc
!.bash_profile
!.vimrc
解决方案
TL;博士
跑
git config --global core.excludesFile <file name for global ignore patterns>
细节
根据我的经验,.gitignore
在您的主目录中适用于全局。
经过一番研究,我发现该设置core.excludesFile
定义了一个要在每个沙箱中读取的忽略文件。在我的 Linux 机器上,默认为~/.gitignore
,而在我的 Windows 机器上,它在其他地方,我不确定在哪里。
在您的情况下,它显然在您的家中,因此您需要对其进行更改,以便您的家 Git 存储库.gitignore
也不是您的全局存储库:
git config --global core.excludesFile ~/.gitignore.global
现在,如果你想在任何地方忽略一些东西,你把它们放在那个文件中,你~/.gitignore
只会应用到你的家庭 Git 存储库本身。
推荐阅读
- sql - 从 CSV NULL 值导入的 PostgreSQL 是文本 - 需要 null
- nginx - Nginx - 部署静态页面
- python - Python 如何安排每一秒的并行脚本?喜欢(cron 工作)
- python - 前瞻和后瞻正则表达式不匹配
- 3d - 如何在这个 Raycaster 引擎中预先计算这个光照层
- python - 如何在 Tkinter 中刷新没有 .mainloop() 函数的窗口?
- r - 如何以“tidyverse”的方式在 R 中按名称重新编码几列?
- macos - https 在 macos 上使用 openssl CA 证书作为受信任
- go - 扫描到具有结构映射的结构
- php - 我如何运行命令来执行 .php 文件?