首页 > 解决方案 > git filter-branch:无法重写分支:您有未暂存的更改

问题描述

我运行这个命令

git filter-branch -f --tree-filter "echo AAAAAAA" --prune-empty --tag-name-filter cat -- --all

并得到以下错误

Proceeding with filter-branch...

Cannot rewrite branches: You have unstaged changes.

以前,我跑

git stash
git stash drop

跑步

git status

给我看

Refresh index: 100% (107206/107206), done.
On branch master

It took 8.70 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
nothing to commit, working tree clean

git 还期待我做什么?


更新:尝试 git status

脚步:

命令:

git stash 

输出

No local changes to save

命令:

git stash drop

输出

No stash entries found.

命令:

git status

输出

Refresh index: 100% (107206/107206), done.
On branch master
It took 8.39 seconds to enumerate untracked files. 'status -uno'

may speed it up, but you have to be careful not to forget to add

new files yourself (see 'git help status').

nothing to commit, working tree clean

命令:

git filter-branch -f --tree-filter "echo AAAAAAA" --prune-empty --tag-name-filter cat -- --all

输出

WARNING: git-filter-branch has a glut of gotchas generating mangled history

     rewrites.  Hit Ctrl-C before proceeding to abort, then use an

     alternative filtering tool such as 'git filter-repo'

     (https://github.com/newren/git-filter-repo/) instead.  See the

     filter-branch manual page for more details; to squelch this warning,

     set FILTER_BRANCH_SQUELCH_WARNING=1.

Proceeding with filter-branch...
Cannot rewrite branches: You have unstaged changes.

标签: gitgit-stashgit-filter-branch

解决方案


最终找到问题的根本原因。

似乎git filter-branch在网络目录中运行并不那么健壮。我将文件复制到本地机器并可以成功运行git filter-branch命令。


推荐阅读