git runtime_error ai_generated true

错误:以下未跟踪的工作树文件将被检出覆盖:file.txt

error: The following untracked working tree files would be overwritten by checkout: file.txt

ID: git/checkout-conflict-with-untracked-files

其他格式: JSON · Markdown 中文 · English
85%修复率
90%置信度
1证据数
2023-09-10首次发现

版本兼容性

版本状态引入弃用备注
2.38.0 active
2.39.0 active
2.40.0 active

根因分析

Git检出会覆盖工作目录中未跟踪的文件,这些文件在目标分支中存在,但在当前分支中未被跟踪。

English

Git checkout would overwrite untracked files in the working directory that are present in the target branch but not tracked in the current branch.

generic

官方文档

https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt---force

解决方案

  1. 将冲突的未跟踪文件移动到安全位置:'mv file.txt file.txt.backup'。然后检出分支。检出后,如果需要可以比较并恢复。
  2. 或者,将未跟踪文件暂存:'git stash --include-untracked'。然后检出分支。之后应用暂存:'git stash pop'。

无效尝试

常见但无效的做法:

  1. Adding the file to .gitignore and retrying checkout. 90% 失败

    The file is already untracked, so .gitignore won't help; it only prevents future tracking. The checkout still sees the file as a conflict.

  2. Using 'git checkout --force' to override the error. 30% 失败

    Force checkout will overwrite the untracked file, potentially losing data. It works but is dangerous.

  3. Running 'git clean -fd' to delete all untracked files blindly. 50% 失败

    This deletes all untracked files, not just the conflicting one, which may remove important files.