laravel 如何使用Git 忽略文件来防止将laravel 的vendor 文件夹和其他配置文件上传到git 分支。什么是正确的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40999954/
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:53:19  来源:igfitidea点击:

How to use Git ignore file to prevent uploading vendor folder and others configuration files of laravel to the git branch. What is the proper way?

gitlaravelgitignore

提问by Rafid Shahriar

After installing laravel debugger package (barryvdh), some of my file like (composer.lock, app.php) has been updated and I don't want to upload those files to my git branch, So that, I added those file name to the gitignore file. After that, I ran "git status" command, and as normally git bash shows me the updated files. Then, I run (git add -All) command to add the files, after that I ran commit and push command, But all of the files that I've just added to the git ignore file, that also uploaded to my branch.

安装 Laravel 调试器包(barryvdh)后,我的一些文件(如composer.lock,app.php)已经更新,我不想将这些文件上传到我的 git 分支,因此,我将这些文件名添加到.gitignore 文件。之后,我运行了“git status”命令,通常 git bash 会向我显示更新的文件。然后,我运行 (git add -All) 命令来添加文件,然后我运行 commit 和 push 命令,但是我刚刚添加到 git ignore 文件中的所有文件,也上传到了我的分支。

回答by Mahfuzul Alam

gitignore- Specifies intentionally untracked files to ignore

gitignore- 指定要忽略的有意未跟踪的文件

If you are using Laravel 5.3, following are the files and directories that are going to be ignored. Here you will find out how they ignored vendordirectory by using /vendorand configuration files like .env

如果您使用的是 Laravel 5.3,以下是将被忽略的文件和目录。在这里,您将了解他们如何通过使用和配置文件来忽略供应商目录,/vendor例如.env

/node_modules
/public/storage
/storage/*.key
/vendor
/.idea
Homestead.json
Homestead.yaml
.env

Here /vendor will ignore vendor directory with all of its sub-directories.

这里 /vendor 将忽略 vendor 目录及其所有子目录。

回答by Delly Fofie

Add your files to the Gitignore file and dont forget to remove them from git with

将您的文件添加到 Gitignore 文件中,不要忘记从 git 中删除它们

git rm -r directory_to_ignoreor git rm file_to_ignore.

git rm -r directory_to_ignoregit rm file_to_ignore

Regards

问候