不明白 gitignore 提示消息

问题描述 投票:0回答:1

我正在尝试理解以下消息:

cap@MacPro-2 wiki-dir % git add -A -- /Users/cap/DOCKER/dante-wiki/volumes/full/content/wiki-dir/extensions/DanteBread/breadCrumbs.js
The following paths are ignored by one of your .gitignore files:
extensions
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"

我觉得令人困惑的问题如下:

在我发出

git add
命令之前,我得到了

cap@MacPro-2 wiki-dir % git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   extensions/DanteBread/COPYING

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   extensions/DanteBread/breadCrumbs.js

然后我得到了

cap@MacPro-2 wiki-dir % git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   extensions/DanteBread/COPYING
    modified:   extensions/DanteBread/breadCrumbs.js

所以Git事实上确实将添加的文件添加到了暂存区,虽然我没有使用

-force

此外,单独的

git check-ignore
表明该文件not 被忽略。

那么为什么我会收到此警告?为什么

git add
声称路径
extensions
被忽略,而
git check-ignore
却找不到这个路径?

git gitignore
1个回答
0
投票

我可以在我的 Linux 系统上重现同样的问题,使用 git 版本 2.42.0 :

设置:

mkdir repo
cd repo
git init
mkdir -p dir1
echo foobarfoobar > dir1/versioned.txt
git add dir1/versioned.txt && git commit -m "created dir1/versioned.txt"
echo dir1 > .gitignore
git add .gitignore && git commit -m "ignoring dir1"

现在:

  • 运行
    git check-ignore dir1/versioned.txt
    将产生空输出,但运行
    git check-ignore dir1/ignored.txt
    甚至
    git check-ignore dir1/doesnt_exist.txt
    将向我显示某些内容被忽略:
# check-ignore does not mention versioned.txt:
$ git check-ignore dir1/versioned.txt
# it does catch ignored files, or even path that don't exist yet and are below dir1/:
$ touch dir1/ignored.txt
$ git check-ignore dir1/ignored.txt
dir1/ignored.txt
$ git check-ignore dir1/doesnt_exist.txt dir1/no_dir/no_file.txt
dir1/doesnt_exist.txt
dir1/no_dir/no_file.txt
  • 修改版本化文件会产生与您的相同的行为:该文件(正确)在
    git status
    中列出,尽管它确实被添加,但我在运行时收到警告
    git add
$ echo "barfoobarfoo" >> dir1/versioned.txt

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   dir1/versioned.txt

no changes added to commit (use "git add" and/or "git commit -a")


$ git add dir1/versioned.txt 
The following paths are ignored by one of your .gitignore files:
dir1
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"

$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
    modified:   dir1/versioned.txt

© www.soinside.com 2019 - 2024. All rights reserved.