.gitignore不忽略文件

时间:2019-10-08 13:10:14

标签: git docker-compose gitignore

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

/.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")

1 个答案:

答案 0 :(得分:2)

添加以下内容:(您不需要全部,但可以使用) 可以更有效地编写它,但是为了简单起见,您要忽略文件夹的内容

.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