简体   繁体   中英

.gitignore does not ignore files

I have a folder with source code. It contains the following files and folders:

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

File .gitignore includes the follwing lines:

/.vs
/bin
/obj

I excpect no file from .vs , bin and obj folders will be included in my repository. But every time I change my repository I see two files from folder obj . They are \obj\Docker\CachedComposeConfigFilePaths.cache and \obj\Docker\MergedDockerCompose.cache . Why git does not ignore them and how do I fix it?

UPD output after git status

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

Add the following: (you don't need them all but it will work) It can be written more efficiently but to make it simple you want to ignore the content of the folders

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

You want to ignore the files in the folder


Another option is that those files are already tracked by git.

Once you add a file to git it will not be ignored even if you add it to the .gitignore

How to remove files tracked by 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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