gpt4 book ai didi

git - .gitignore 的奇怪行为

转载 作者:太空狗 更新时间:2023-10-29 14:34:41 25 4
gpt4 key购买 nike

给你:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com