【问题标题】:Can't understand how gitignore ignores the folders无法理解 gitignore 如何忽略文件夹
【发布时间】:2011-04-21 00:34:01
【问题描述】:

我想为我的 Magento 项目创建存储库。根目录中有很多文件夹和文件,我有时只更改一个文件夹:app/code/local/

我想忽略的所有其他内容。但是..不能。我的 .gitignore 文件:

*
!app/code/local/
!app/code/local/*

然后当我尝试将文件夹添加到 repo 时出现错误:

git add app/code/local/Mds/

The following paths are ignored by one of your .gitignore files:
app
Use -f if you really want to add them.
fatal: no files added

有人可以帮忙吗?

【问题讨论】:

    标签: git gitignore


    【解决方案1】:

    尝试在下面按您的需要忽略:

    /*
    !/app/
    /app/*
    !/app/code/
    /app/code/*
    !/app/code/local/
    

    以下讨论很有帮助:http://git.661346.n2.nabble.com/negated-list-in-gitignore-no-fun-td1675067.html,尤其是来自 Linus 的以下内容:

    That's by design. You've chosen to ignore those directories; they match "*" themselves. Thus, 'git add .' doesn't descend into them looking for files.

    所以基本上,对于您必须进入的每个级别,取消忽略该文件夹,并忽略该文件夹中的内容。

    【讨论】:

    • 我不敢相信我不工作。我什至在 app/code/local 下创建了新文件夹,但错误是一样的......
    • 你必须做一些不同的事情。在我的编辑之后,我意识到我的答案现在与@Nick 相同,所以我们两个人不会错 :) 。我在一个虚拟仓库中对其进行了测试!
    • Pal 它正在工作 =)) 非常感谢。你是怎么得到的)
    • 就像在我编辑的回复中一样,Linus 在我提供的链接中的回复帮助我弄清楚了 Git 是如何处理它的。
    【解决方案2】:

    这个 .gitignore 是否在 repo 的根目录中?

    试试这个:

    /*
    !/app/code/local
    

    【讨论】:

    • 抱歉没有帮助 =( .gitignore 在根文件夹中。
    【解决方案3】:

    根据the documentation

    “如果文件的父目录被排除,则不能重新包含该文件。”

    例如,如果您已经在使用存储库并告诉 Git 忽略父目录,进行了一些提交,然后返回并尝试允许排除目录的某些子目录,它将不包含该目录子目录即使您的.gitignore 文件是正确的。要解决这个问题,您需要强制添加它(使用 -f 标志):

    git add -f {file}
    

    完成此操作后,将跟踪后续更改。

    【讨论】:

      猜你喜欢
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 2021-09-29
      • 1970-01-01
      • 2021-09-24
      • 1970-01-01
      • 2018-01-12
      相关资源
      最近更新 更多