首页 > 解决方案 > 在纱线工作区中运行“git clean -xdf”时,跟踪文件被删除

问题描述

git clean -xdf在带有 yarn 工作区的 repo 中运行时,工作区的内容将被删除。

考虑这个文件夹结构:

运行git clean -xfd粗体文件(跟踪的源代码控制文件)后被删除!即使 clean 根本不应该影响跟踪的文件。

我相信这是一个纱线工作区错误。我打开了一个问题@yarn: https ://github.com/yarnpkg/yarn/issues/7536

有没有人遇到过这个错误?有没有人有解决方法或知道这种行为的根本原因?

对于有兴趣亲眼看到该错误的任何人,我创建了一个使其易于重现的存储库: https ://github.com/Shmulik-Kravitz/yarn-with-git-bug

重现的步骤在里面。

输出yarn --verbose(很长): https ://github.com/Shmulik-Kravitz/yarn-with-git-bug/blob/master/yarn%20log

输出git clean -xdf

Removing node_modules/

输出git status

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    workspace1/index.js
        deleted:    workspace1/package.json
        deleted:    workspace2/index.js
        deleted:    workspace2/package.json

no changes added to commit (use "git add" and/or "git commit -a")

标签: gityarnpkgyarn-workspaces

解决方案


如果您使用的是 Windows,我敢打赌最可能的原因是以下问题:https ://github.com/git-for-windows/git/issues/607 。Git 确实在删除连接点的内容。

我可以使用“git version 2.22.0.windows.1”重现您的问题,但升级到“git version 2.23.0.windows.1”后不再看到它。


推荐阅读