git runtime_error ai_generated true

error: Your local changes to the following files would be overwritten by merge: file.txt Please commit your changes or stash them before you merge.

ID: git/merge-branch-refused-due-to-uncommitted-changes

Also available as: JSON · Markdown · 中文
90%Fix Rate
87%Confidence
1Evidence
2023-06-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.28.0 active — — —
git 2.34.0 active — — —
git 2.41.0 active — — —

Root Cause

Uncommitted changes in the working directory conflict with incoming merge changes, and Git refuses to proceed to prevent data loss.

generic

中文

工作目录中的未提交更改与传入的合并更改冲突,Git 拒绝继续以防止数据丢失。

Official Documentation

https://git-scm.com/docs/git-merge

Workarounds

  1. 90% success Stash your changes: git stash push -m 'temp stash', then merge, then apply stash: git stash pop
    Stash your changes: git stash push -m 'temp stash', then merge, then apply stash: git stash pop
  2. 85% success Commit your changes: git add file.txt && git commit -m 'save local changes', then merge.
    Commit your changes: git add file.txt && git commit -m 'save local changes', then merge.
  3. 80% success If the changes are not needed, discard them: git checkout -- file.txt, then merge.
    If the changes are not needed, discard them: git checkout -- file.txt, then merge.

中文步骤

  1. Stash your changes: git stash push -m 'temp stash', then merge, then apply stash: git stash pop
  2. Commit your changes: git add file.txt && git commit -m 'save local changes', then merge.
  3. If the changes are not needed, discard them: git checkout -- file.txt, then merge.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Permanently discards all local changes, which may be unintended.

  2. 70% fail

    Wipes all uncommitted changes, including those in other files.

  3. 100% fail

    Does not bypass the error; the merge still refuses to proceed.