繁体   English   中英

.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 output

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM