newren / git-filter-repo

Quickly rewrite git repository history (filter-branch replacement)
Other
8.52k stars 708 forks source link

Refusing to destructively overwrite repo history since #522

Closed robert-elles closed 1 month ago

robert-elles commented 12 months ago

Hello, running git-filter-repo --path git-crypt --invert-paths I get:

Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
  (you have untracked changes)
Please operate on a fresh clone instead.  If you want to proceed
anyway, use --force.

I get this on a repo that was just cloned. Using --force will corrupt my repo and remove the remote repo.

noremacskich commented 10 months ago

For others that come across this, I found out that untracked changes does include any files / folders that .gitignore might be ignoring.

To see those, run this command

git status --ignored

In my case, there was a node_modules folder among others that got automatically added with the IDE I was using to clone the repo.

Once I removed those, it worked

jjanuszkiewicz commented 8 months ago

I have a completely clean repo and it still complains, any idea why that could be?

$ git status --ignored
On branch master
nothing to commit, working tree clean

$ git-filter-repo --path [...]
Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
  (expected freshly packed repo)
Please operate on a fresh clone instead.  If you want to proceed
anyway, use --force.
jjanuszkiewicz commented 8 months ago

Worked just fine with --force, not sure what the problem was.

alissa-huskey commented 7 months ago

Just in case anyone else was running into this problem due to __pycache__ directories somehow being created in between removing the directory and running git-filter-repo again, you can disable the generation of those directories.

export PYTHONDONTWRITEBYTECODE=1
find . -type d -name __pycache__ -exec rm -r {} \+
git-filter-repo --path [...]
newren commented 1 month ago

I put a pycache workaround into e672e43ba597 (filter-repo: ignore pycache untracked files for fresh clone check, 2024-08-05), which I think should fix this issue. (That commit isn't part of a release yet.). If you try again and hit the issue after updating to a version with that commit, please do report again.

Thanks @alissa-huskey for pointing out that some python versions would stick pycache files underneath the repository of interest.