laravel .gitignore 不忽略文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39014896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:19:49  来源:igfitidea点击:

.gitignore not ignoring folder

gitlaravelsmf-forum

提问by Vertisan

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 中有一个项目,我在公共目录中有论坛,我不想将它推送到存储库,所以我用 .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?

但是,该条目仍然出现在Git 状态
这是我的树:
+...
+ public
++ forum
+++...
+...
问题出在哪里?

Directory structure enter image description here

目录结构 在此处输入图片说明

Git status enter image description here

Git 状态 在此处输入图片说明

回答by KmasterYC

In .gitignoreadd

在 。gitignore添加

public/forum

Run

git rm --cached -r public/forum

回答by BartBog

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.

问题是这个文件夹已经在你的索引中了(你之前提交过)。对索引中文件的更改将始终处于“git 状态”。只会忽略该文件夹中的新文件。

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

要解决这个问题。在https://stackoverflow.com/a/38304114/2274140上查看我的回答

回答by sarfaraz shaikh

Do the following to trigger the gitignore:

执行以下操作以触发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"
    
  1. 提交您要修复的存储库中的所有未决更改并推送它。

  2. 从 git 索引中删除所有内容以刷新您的 git 存储库。这是安全的。使用这个命令:

    git rm -r --cached .
    
  3. 将所有内容添加回 repo,这可以使用以下命令完成:

    git add .
    
  4. 使用以下命令提交这些更改:

    git commit -m "Gitignore issue fixed"