无法理解 gitignore 如何忽略文件夹

发布于 2024-11-02 14:27:24 字数 419 浏览 4 评论 0原文

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

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

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

然后,当我尝试将文件夹添加到存储库时,出现错误:

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

任何人都可以帮忙解决这个问题吗?

I want to create repository for my Magento project. There are lots of folders and files in root directory and I change time to time only one folder: app/code/local/

Everything else I want to ignore. But.. can't. My .gitignore file:

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

Then when I try to add folder to repo I get an error:

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

Can anyone please help with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷→糖丶微凉 2024-11-09 14:27:24

尝试如下忽略您需要的内容:

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

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

这是设计使然。您选择忽略这些目录;它们匹配“*”
他们自己。因此,“git add”。不会深入其中寻找文件。

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

Try below to ignore like you need:

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

The following discussion was helpful: http://git.661346.n2.nabble.com/negated-list-in-gitignore-no-fun-td1675067.html , especially the following from 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.

So basically, for each level you have to go in, unignore that folder, and ignore contents within that folder.

烦人精 2024-11-09 14:27:24

这个 .gitignore 是在仓库的根目录中吗?

试试这个:

/*
!/app/code/local

Is this .gitignore in the root of the repo?

Try this:

/*
!/app/code/local
[浮城] 2024-11-09 14:27:24

根据文档

“如果排除某个文件的父目录,则无法重新包含该文件。”

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

git add -f {file}

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

According to the documentation:

"It is not possible to re-include a file if a parent directory of that file is excluded."

For example, if you had already been working with the repository and told Git to ignore the parent directory, made some commits, and then went back and tried to allow some sub-directory of the excluded directory, it will not include that sub directory even if your .gitignore file is correct. To get around this, you need to force add it (with the -f flag):

git add -f {file}

Once this has been done, subsequent changes will be tracked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文