admin管理员组

文章数量:1122832

I have been using @wordpress/env for a few weeks, starting it with npm run wp-env start. Since this morning, that now fails with:

> wp-env "start"

✖ error: Your local changes to the following files would be overwritten by checkout:
        wp-content/themes/twentytwentyone/assets/css/ie.css
        wp-content/themes/twentytwentyone/assets/sass/01-settings/file-header.scss
        wp-content/themes/twentytwentyone/style-rtl.css
        wp-content/themes/twentytwentyone/style.css
Please commit your changes or stash them before you switch branches.
Aborting

GitError: error: Your local changes to the following files would be overwritten by checkout:
        wp-content/themes/twentytwentyone/assets/css/ie.css
        wp-content/themes/twentytwentyone/assets/sass/01-settings/file-header.scss
        wp-content/themes/twentytwentyone/style-rtl.css
        wp-content/themes/twentytwentyone/style.css
Please commit your changes or stash them before you switch branches.
Aborting

    at Object.action (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1228:25)
    at PluginStore.exec (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1263:29)
    at /home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1627:43
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1625:16)
    at GitExecutorChain.<anonymous> (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1609:44)
    at Generator.next (<anonymous>)
    at fulfilled (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:55:24) {
  task: {
    commands: [ 'checkout', '6.1.1' ],
    format: 'utf-8',
    parser: [Function: parser]
  }
}

The error message talks about "your local changes", but I have not modified any files in the twentytwentyone theme folder. wp-env seems to have brought this on itself.

I have tried removing the Docker image for WordPress and starting again, but the problem persists. I have tried wp-env start --update - that does not fix it either. The Docker container does not stay up so I cannot get into it (with docker exec) to remove those changes.

Any idea how I can get wp-env working again?

I have been using @wordpress/env for a few weeks, starting it with npm run wp-env start. Since this morning, that now fails with:

> wp-env "start"

✖ error: Your local changes to the following files would be overwritten by checkout:
        wp-content/themes/twentytwentyone/assets/css/ie.css
        wp-content/themes/twentytwentyone/assets/sass/01-settings/file-header.scss
        wp-content/themes/twentytwentyone/style-rtl.css
        wp-content/themes/twentytwentyone/style.css
Please commit your changes or stash them before you switch branches.
Aborting

GitError: error: Your local changes to the following files would be overwritten by checkout:
        wp-content/themes/twentytwentyone/assets/css/ie.css
        wp-content/themes/twentytwentyone/assets/sass/01-settings/file-header.scss
        wp-content/themes/twentytwentyone/style-rtl.css
        wp-content/themes/twentytwentyone/style.css
Please commit your changes or stash them before you switch branches.
Aborting

    at Object.action (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1228:25)
    at PluginStore.exec (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1263:29)
    at /home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1627:43
    at new Promise (<anonymous>)
    at GitExecutorChain.handleTaskData (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1625:16)
    at GitExecutorChain.<anonymous> (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:1609:44)
    at Generator.next (<anonymous>)
    at fulfilled (/home/alice/wp-demo-theme/node_modules/simple-git/dist/cjs/index.js:55:24) {
  task: {
    commands: [ 'checkout', '6.1.1' ],
    format: 'utf-8',
    parser: [Function: parser]
  }
}

The error message talks about "your local changes", but I have not modified any files in the twentytwentyone theme folder. wp-env seems to have brought this on itself.

I have tried removing the Docker image for WordPress and starting again, but the problem persists. I have tried wp-env start --update - that does not fix it either. The Docker container does not stay up so I cannot get into it (with docker exec) to remove those changes.

Any idea how I can get wp-env working again?

Share Improve this question edited Nov 18, 2022 at 9:17 Duncan T asked Nov 17, 2022 at 16:24 Duncan TDuncan T 113 bronze badges 4
  • Do the mentioned files have changes in them and are they meant to be in there? – kero Commented Nov 17, 2022 at 16:36
  • 3 looks like you've modified the twentytwentyone theme directly instead of creating a child theme to store your changes. Copying the folder was also an option. Fixing this means you need to undo those changes to fix the problem. Note that you shouldn't be using core WP develop for anything other than contributing to WordPress itself, it's not intended for client work/personal projects/etc – Tom J Nowell Commented Nov 17, 2022 at 16:46
  • I have not modified any files in the folder described in the error message. This seems to be entirely down to @wordpress/env. – Duncan T Commented Nov 18, 2022 at 9:13
  • A few weeks after I posted this, the problem mysteriously went away without me changing anything. Now it is back again. I haven't changed anything. The process of starting wp-env clearly pulls something onto my machine, so presumably that has changed. Has anyone else seen this kind of problem? – Duncan T Commented Apr 4, 2023 at 9:28
Add a comment  | 

2 Answers 2

Reset to default 1

I had the same problem with a completely new installation of wp-env.

In my case, the error apparently originated from wp-env downloading PHPUnit in node_modules/@wordpress/env/lib/download-wp-phpunit.js.

Commenting line 137 (version 5.14.0) in download-wp-phpunit.js resolved the problem:

log( `Fetching ${ ref }.` );
await git.raw( fetchRaw );

log( `Checking out ${ ref }.` );
// await git.checkout( ref ); <--- Comment this line

onProgress( 1 );

Please note that this is only a temporary solution, and the problem will surface again after an update of wp-env.

If you have wp-env installed globally and locally, be sure to use the right one after the change (or change both, if necessary).

This will likely impact the usage of PHPUnit. I'm just trying out wp-env, so I cannot comment on the scope of this change. Someone with more experience on the tool and a deeper understanding should probably dig deeper into this if more people are affected.

The problem is that wp-env pulls data onto your local machine like plugins or themes when you use a git repo as a source in your .wp-env.json

Run wp-env install-path. This command will output a path to a local folder where wp-env caches the themes and plugins data. There, you can find the folder (in your case it should be the TwentyTwenty theme's folder) and inside that folder either:

  1. Reset your branch to a clean state: git checkout -- .
  2. The nuclear option - just delete the whole folder. Be advised that this will remove all your customizations!

本文标签: