git - .gitignore 的奇怪行为

标签 git

给你:

root@Dell: /tmp # mkdir test; cd test
root@Dell: /tmp/test # git init
Initialized empty Git repository in /tmp/test/.git/
root@Dell: /tmp/test # mkdir foo
root@Dell: /tmp/test # touch foo/a
root@Dell: /tmp/test # git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       foo/
nothing added to commit but untracked files present (use "git add" to track)
root@Dell: /tmp/test # cat > .gitignore << EOF
> *
> !foo/
> EOF
root@Dell: /tmp/test # git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

任何人都可以解释为什么空的 .gitignore 与以下内容不同:

*
!foo/

在这种情况下?

最佳答案

您设法使目录 foo “不被忽略”,但 foo 中的所有内容仍然与“*”模式匹配。
这将从 gitignore '*' 初始指令中删除 foo 内容:

*
!/foo/
!/foo/*

或者:

*
!/foo/

foo中加上一个.gitignore:

!*

关于git - .gitignore 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5056375/

相关文章:

git - 应该提交 .last_build_id 吗?

git - 克隆/推送 Git Repos 时出错 443 : Bad access, 但未使用代理

具有相同名称但大小写不同的文件的 Git rebase 问题

Git 子模块警告 'multiple configurations found'

ruby-on-rails - merge 分支和包更新后不推送到 heroku

git - 如何 merge 到远程标签或提交 ID

git - CMake 无法检测 Git 版本

bash - git filter repo 可以根据日期从许多 repos 交织提交中创建一个 monorepo 吗?

git - 如何在ansible中转发ssh key 以从源头 checkout 目标机器上的git存储库?

linux - 安装 GitLab 并让它在子域上运行