gitignore does not ignore folder

社会主义新天地 提交于 2019-11-27 10:35:23
Reck

I'm guessing this folder has been checked into git before?

Run git rm -r --cached <folder> and check again.

For me, the accepted answer was part of the solution, not the entire solution. Maybe, the other steps that I'm about to post were obvious, but I missed them first. Here's the steps I took to ensure my .gitignore file ignored the folder I wanted it to ignore:

  1. Commit any changes that you need to fix/change.
  2. Run this command: git rm -r --cached . (which removes everything from the git index in order to refresh your git repository)
  3. Then run this command: git add . (to add everything back to the repo)
  4. Finally, commit these changes using git commit -m ".gitignore Fixed"

You can find the link to the article from where I found the solution here.

I was having this issue and I realized git was actually ignoring the files/folders correctly, but my code editor (Visual Studio Code) was just buggy and not "greying them out" properly in the UI sidebar. I restarted VSCode and they were greyed out as expected.

As an addition to the accepted answer

git rm -r --cached /foo/bar/
git status

When i do that, the terminal shows a bunch of rm for files in that directory. So to prevent another commit that might unnecessarily affect remote, I i did:

git reset HEAD *
git status

After that, it said nothing to commit and when i modify files inside /foo/bar/ and do a git status i still get nothing to commit.

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