git
runtime_error
ai_generated
true
error: The following untracked working tree files would be overwritten by checkout: file.txt
ID: git/checkout-conflict-with-untracked-files
85%Fix Rate
90%Confidence
1Evidence
2023-09-10First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.38.0 | active | — | — | — |
| 2.39.0 | active | — | — | — |
| 2.40.0 | active | — | — | — |
Root Cause
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中文
Git检出会覆盖工作目录中未跟踪的文件,这些文件在目标分支中存在,但在当前分支中未被跟踪。
Official Documentation
https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt---forceWorkarounds
-
95% success Move the conflicting untracked files to a safe location: 'mv file.txt file.txt.backup'. Then checkout the branch. After checkout, you can compare and restore if needed.
Move the conflicting untracked files to a safe location: 'mv file.txt file.txt.backup'. Then checkout the branch. After checkout, you can compare and restore if needed.
-
90% success Alternatively, stash the untracked files: 'git stash --include-untracked'. Then checkout the branch. Later apply the stash: 'git stash pop'.
Alternatively, stash the untracked files: 'git stash --include-untracked'. Then checkout the branch. Later apply the stash: 'git stash pop'.
中文步骤
将冲突的未跟踪文件移动到安全位置:'mv file.txt file.txt.backup'。然后检出分支。检出后,如果需要可以比较并恢复。
或者,将未跟踪文件暂存:'git stash --include-untracked'。然后检出分支。之后应用暂存:'git stash pop'。
Dead Ends
Common approaches that don't work:
-
Adding the file to .gitignore and retrying checkout.
90% fail
The file is already untracked, so .gitignore won't help; it only prevents future tracking. The checkout still sees the file as a conflict.
-
Using 'git checkout --force' to override the error.
30% fail
Force checkout will overwrite the untracked file, potentially losing data. It works but is dangerous.
-
Running 'git clean -fd' to delete all untracked files blindly.
50% fail
This deletes all untracked files, not just the conflicting one, which may remove important files.