git runtime_error ai_generated true

无法重写分支:您有未暂存的更改

Cannot rewrite branches: You have unstaged changes.

ID: git/filter-branch-abort

其他格式: JSON · Markdown 中文 · English
88%修复率
84%置信度
1证据数
2024-03-01首次发现

版本兼容性

版本状态引入弃用备注
git 2.44.0 active
git 2.45.0 active
git 2.46.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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

无效尝试

常见但无效的做法:

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

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

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

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