【问题标题】:gitignore file doesn't ignoregitignore 文件不会忽略
【发布时间】:2018-05-02 14:34:35
【问题描述】:

我是 git hub 的新手,我用以下行更改了 .gitignore 文件。

/src/main/webapp/app/app.constants.js

然后我构建项目。但是当我在 git bash 中键入 git status 时,app.constants.js 文件仍然显示为修改后的文件。那么我哪里错了?

【问题讨论】:

  • 并且在测试之前是否需要再次提交gitignore文件到git?

标签: github gitignore git-bash


【解决方案1】:

.gitignore 仅适用于未跟踪的文件。根据the documentation, git status 只为您提供工作树的状态。当您提交更改时,忽略将启动。所以没什么出乎意料的。

如果你想忽略被忽略文件的状态,你可以这样做git update-index --assume-unchanged <file>

或者你可以清理 git 缓存:从存储库中删除它们 git rm --cached <file>

【讨论】:

    【解决方案2】:

    / 开头的路径是指它的绝对路径。您可能试图引用src 子目录。删除前导 / 就可以做到这一点(参考相对目录)。

    【讨论】:

    • 即使.gitignore 中的给定路径也以“/path..”的形式出现,它被评估为相对路径,方式如下:<location of .gitignore file>/path...
    • @dbi 你有这方面的资料吗?如果你这样做,我会将此答案标记为不正确。
    • A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c". - git documentation.
    • @Alexey Ten claims "/path" is evaluated as <root git repo>/path 但我不知道这两个语句中哪一个是正确的,也没有时间在 atm 测试它。如果有人可以澄清这一点,请随时这样做。
    猜你喜欢
    • 1970-01-01
    • 2021-09-29
    • 2021-09-24
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 2019-04-29
    相关资源
    最近更新 更多