在 yarn 工作区中 运行 "git clean -xdf" 时删除跟踪文件

Tracked files are deleted when running "git clean -xdf" in yarn workspaces

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

考虑这个文件夹结构:

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

我认为这是一个 yarn workspaces 错误。我已经打开了一个问题@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")

如果您在 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" 后就看不到它了。