简体   繁体   中英

Git ignoring the .gitignore file and saying the .DS_Store file is modified

I don't want my MacBook's .DS_Store-files to be committed to my Git repository.

Unfortunately my .gitignore and even .gitignore_global seem to be ignored completely.

Any ideas what could be the reason?

 ujjain:~/Dropbox/workspace| (HEAD) [+1] | feature/Jenkinsfile [+1]
$ cat .gitignore
...

# Mac OS Test
.DS_Store
 ujjain:~/Dropbox/workspace| (HEAD) [+1] | feature/Jenkinsfile [+1]
$ git status
On branch feature/Jenkinsfile
Your branch is up to date with 'origin/feature/Jenkinsfile'.

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:   .DS_Store

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

You may have committed this file previously. Try this to remove it:

git rm --cached .DS_Store

Your .DS_Store has been committed before it had been added in the .gitignore . You remove it from your repo with:

git rm --cached .DS_Store
git commit -m '.DS_Store untracked'

The --cached option will remove the file from the index only, but will not delete the file itself.

Once this will be done, the file will not be tracked by Git anymore and will be properly ignored.

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