Why doesn't Git ignore my specified file?

前端 未结 13 1551
野性不改
野性不改 2020-11-28 17:12

I added the following line to .gitignore:

sites/default/settings.php

but when I type git status it shows the file

13条回答
  •  暖寄归人
    2020-11-28 18:09

    One thing that I think has been missed in the excellent answers here is the existence if another *.gitignore* or multiple of them.

    In a case, I had cloned a repo and could not figure out why a "ignored" file was being added again when running git add. It worked out that there was another .gitignore in a subfolder and that was overriding the one in the root folder.

    /.gitignore
    /some-folder/.gitignore
    /some-folder/this-file-keeps-getting-staged
    

    The

    root /.gitignore

    was ignoring this-file-keeps-getting-staged

    The

    /some-folder/.gitignore

    did not have a specification to ignore "this-file-keeps-getting-staged" file.

    And hence the issue.

    One of the things is to simply search for multiple .gitignore files in the hierarchy. And figure out the rules as they apply.

提交回复
热议问题