Can't understand how gitignore ignores the folders

↘锁芯ラ 提交于 2019-11-27 16:26:48

问题


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?


回答1:


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.




回答2:


Is this .gitignore in the root of the repo?

Try this:

/*
!/app/code/local



回答3:


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.



来源:https://stackoverflow.com/questions/5738204/cant-understand-how-gitignore-ignores-the-folders

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!