简体   繁体   中英

Git not ignoring untracked file

I sometimes use VSCode, which sometimes results in .vscode folders spontaneously appearing. I am fine with this, but I don't want them in my git repositories, so I added them to my global gitignore.

Yet in at least one repository running git status still shows an untracked .vscode directory. Output from relevant commands follows

.config on  canon [?] via ❄️  impure 
❯ gc ~/.config/git/ignore           
.*.swp
result
.vscode/
__pycache__/

.config on  canon [?] via ❄️  impure 
❯ git st                 
On branch canon
Your branch is up to date with 'origin/canon'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    nixpkgs/home-manager/scripts/.vscode/

nothing added to commit but untracked files present (use "git add" to track)

man 5 gitignore says that ignore patterns will match on any level unless the file has a / at the beginning or middle - which this pattern doesn't. Why, then, does the directory show up as untracked in git status ?

Patterns in a repository's own .gitignore take precedence over global patterns. If the repository's own .gitignore file contains a line that negates a line from $env:XDG_DATA_HOME/git/ignore , (in this case the line was !/nixpkgs/** ) the file will not be ignored.

git check-ignore is a useful tool for figuring out why a file is or isn't being 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