克隆的 Laravel 项目无法正常工作

克隆的 Laravel 项目无法正常工作

我有 Windows 10、WSL2 和 Docker。

我从 GitHub 克隆了一个存储库,当我尝试时sail up,我收到此消息:/usr/bin/env: ‘sh\r’: No such file or directory

以下内容来自 laravel 网站,我相信它可以解决我的问题:

docker run --rm \
    -u "$(id -u):$(id -g)" \
    -v $(pwd):/var/www/html \
    -w /var/www/html \
    laravelsail/php81-composer:latest \
    composer install --ignore-platform-reqs

上述代码的来源:https://laravel.com/docs/8.x/sail#installing-composer-dependencies-for-existing-projects

我试过了docker run laravelsail/php81-composer:latest。我也试过了docker run --rm -v $(pwd):/app composer/composer install。两次我都继续成功/usr/bin/env: ‘sh\r’: No such file or directory

你能指导我如何让我的船帆运转起来,以便我能看到我的项目吗localhost

谢谢。

我的composer.json文件:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.2",
        "laravel/sanctum": "^2.14.1",
        "laravel/tinker": "^2.7"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/breeze": "^1.9",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10",
        "spatie/laravel-ignition": "^1.0"
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

答案1

看来运行后git config --global core.autocrlf false您之前克隆的实际存储库尚未受到影响,您需要刷新存储库。

您可以通过两种方法实现此目标:

  1. 删除您首先克隆的存储库,然后克隆回来,但现在 autcrlf 应该生效。
  2. 重新规范化存储库

对于选项 2:

将当前文件保存在 Git 中,这样您的工作就不会丢失。

$ git add . -u
$ git commit -m "Saving files before refreshing line endings"

将所有更改过的文件添加回来并规范化行尾。

$ git add --renormalize .

显示重写的、规范化的文件。

$ git status

将更改提交到您的存储库。

$ git commit -m "Normalize all the line endings"

来源:https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings#refreshing-a-repository-after-changing-line-endings

相关内容