.gitignore not ignoring folder

故事扮演 提交于 2019-12-04 17:10:13

问题


I have a project in Laravel and I have forum in public directory which I don't want to push it to repository, so I write in .gitignore:

### Laravel ###
vendor/
node_modules/

# Laravel 5 & Lumen specific
bootstrap/cache/
.env.*.php
.env.php
.env

# SMF
public/forum/

# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
.rocketeer/

However, the entry still appears in Git status
Here is my tree with it:
+...
+ public
++ forum
+++...
+...
Where is the problem?

Directory structure

Git status


回答1:


The problem is that this folder is already in your index (you committed it at an earlier moment). Changes to files in the index will always be in "git status". Only new files in that folder will be ignored.

To fix it. See my answer on https://stackoverflow.com/a/38304114/2274140




回答2:


In .gitignore add

public/forum

Run

git rm --cached -r public/forum



回答3:


Do the following to trigger the gitignore:

  1. Commit all your pending changes in the repository which you want to fix and push that.

  2. Remove everything from the git index in order to refresh your git repository. This is safe. Use this command:

    git rm -r --cached .
    
  3. Add everything back into the repo, which can be done using this command:

    git add .
    
  4. Commit these changes, using this command:

    git commit -m "Gitignore issue fixed"
    


来源:https://stackoverflow.com/questions/39014896/gitignore-not-ignoring-folder

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