【问题标题】:Git ignore is not ignoring the netbeans private filesGit忽略不忽略netbeans私有文件
【发布时间】:2015-05-27 07:31:41
【问题描述】:

当我执行 git status 时,netbeans private.xml 会出现问题,我尝试在 git ignore 中添加几种方法。但 gitignore 根本不会忽略它。

git status
On branch master
Your branch is up-to-date with 'origin/master'.

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:   .gitignore
   modified:   nbproject/private/private.xml
...

我的 git 忽略文件是

node_modules/
dist/
*.log
nbproject/private/*    
*.bak
*.orig
*~
*.log
*private.xml

都试过了 nbproject/私人/* 和 *private.xml 在同一个文件中。

【问题讨论】:

    标签: git netbeans gitignore


    【解决方案1】:

    不会忽略已跟踪的文件:您需要先从索引中删除。

    git rm --cached private.xml 
    git add -u .
    git commit -m "Record deletion of private.xml from the index"
    

    --cached 选项确保文件保留在磁盘上)

    然后你可以在.gitignore中添加(不需要'*')

    private.xml 
    

    注意:无论何时忽略或不忽略文件,您都可以检查适用于哪个.gitignore 规则:

    git check-ignore -v -- private.xml
    

    【讨论】:

      【解决方案2】:

      您的文件已添加到 git 存储库。
      一旦文件被添加(不是未跟踪),将其添加到 .gitignore 将不会忽略它,因为它已经在存储库中,因此您必须从存储库中 remove 它,提交文件的删除,然后它将被忽略。

      请参阅上面的VonC 代码了解如何操作。

      要了解的重要一点是,一旦文件已经提交,将其添加到 git ignore 将不会忽略它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-31
        • 1970-01-01
        • 2016-04-09
        • 1970-01-01
        • 2022-08-21
        • 1970-01-01
        相关资源
        最近更新 更多