.gitignore 不忽略文件

.gitignore does not ignore files

我有一个包含源代码的文件夹。它包含以下文件和文件夹:

/.git
/.vs
/bin
/obj
/src
/tests
.gitignore
docker-compose.dcproj
docker-compose.yml

文件 .gitignore 包含以下行:

/.vs
/bin
/obj

我预计 .vsbinobj 文件夹中的文件不会包含在我的存储库中。但是每次我更改存储库时,我都会看到文件夹 obj 中的两个文件。他们是 \obj\Docker\CachedComposeConfigFilePaths.cache\obj\Docker\MergedDockerCompose.cache。为什么 git 不忽略它们,我该如何解决?

git status

后的 UPD 输出
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   obj/Docker/CachedComposeConfigFilePaths.cache
        modified:   obj/Docker/MergedDockerCompose.cache
        modified:   // another files

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        //some files

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

添加以下内容:(您不需要全部但它会起作用) 可以写的更高效但是为了简单你想忽略文件夹的内容

.git/**
**/.vs/**
**/bin/**
**/obj/**

您想忽略文件夹中的文件


另一种选择是这些文件已经被 git 跟踪。

将文件添加到 git 后,即使将其添加到 .gitignore

,它 也不会 被忽略

如何删除 git

跟踪的文件
# Remove any file you have already committed and you wish to ignore
git rm -rf --cached .vs/*

# now add the ignored pattern to your .gitignore file
git add .

# commit and push the removal of the ignored files.
git commit -m "Removed idea files"

#Push the changes
git push