Search code examples
gitgit-stashgit-filter-branch

git filter-branch: Cannot rewrite branches: You have unstaged changes


I run this command

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

And get the following error

Proceeding with filter-branch...

Cannot rewrite branches: You have unstaged changes.

Previously, I ran

git stash
git stash drop

running

git status

shows me

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

What else is git expecting me to do?


Update: trying git status

steps:

command:

git stash 

output

No local changes to save

command:

git stash drop

output

No stash entries found.

command:

git status

output

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

command:

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

output

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.

Solution

  • Eventually find the problem root cause.

    It seems that running git filter-branch in a network directory is not that robust. I copied the files to the local machine and could successfully run git filter-branch command.