给你:
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/