git runtime_error ai_generated true

Cannot rewrite branches: You have unstaged changes.

ID: git/filter-branch-abort

Also available as: JSON · Markdown · 中文
88%Fix Rate
84%Confidence
1Evidence
2024-03-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.44.0 active
git 2.45.0 active
git 2.46.0 active

Root Cause

Attempting to run git filter-branch with uncommitted changes in the working directory, which could be lost during history rewriting.

generic

中文

尝试在存在未提交更改的工作目录中运行git filter-branch,这些更改可能在历史重写过程中丢失

Official Documentation

https://git-scm.com/docs/git-filter-branch

Workarounds

  1. 90% success Commit or stash changes first: git stash push -m 'temp' && git filter-branch --tree-filter '...' HEAD && git stash pop
    Commit or stash changes first: git stash push -m 'temp' && git filter-branch --tree-filter '...' HEAD && git stash pop
  2. 85% success Use 'git stash' and then after filter-branch, manually re-apply: git stash && git filter-branch ... && git stash apply --index
    Use 'git stash' and then after filter-branch, manually re-apply: git stash && git filter-branch ... && git stash apply --index

中文步骤

  1. Commit or stash changes first: git stash push -m 'temp' && git filter-branch --tree-filter '...' HEAD && git stash pop
  2. Use 'git stash' and then after filter-branch, manually re-apply: git stash && git filter-branch ... && git stash apply --index

Dead Ends

Common approaches that don't work:

  1. Running 'git stash' and then filter-branch without popping stash 80% fail

    Stash is preserved but filter-branch rewrites history; stash may reference old commits

  2. Using 'git filter-branch -f' to force the operation 95% fail

    Force flag does not exist for filter-branch; it will still abort with the same error