gpt4 book ai didi

git - 如何使用 git filter-branch 从我的存储库中删除文件? ("you need to run this command from the toplevel of the working tree")

转载 作者:行者123 更新时间:2023-12-04 15:54:13 24 4
gpt4 key购买 nike

根据git documentation ,我可以像这样从我的 repo 历史中删除一个文件:

git filter-branch --tree-filter 'rm -rf filename' HEAD

我试过了,得到了这个错误:

You need to run this command from the toplevel of the working tree.

所以,我试过了,得到了同样的错误:

git filter-branch --index-filter 'rm -f  /dist/bikeMap.html' HEAD

查了多个stackoverflow的问题,我也试过了

git filter-branch --index-filter 'rm -f  /dist/bikeMap.html' master..HEAD
git filter-branch --tree-filter 'rm -f /dist/bikeMap.html' --all
git filter-branch --tree-filter 'rm -f /dist/bikeMap.html' -- --all
git filter-branch --tree-filter 'rm -f /dist/bikeMap.html' master

等等。都给出相同的错误。

git status

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

我的 git 版本是 2.11.0

编辑:我现在也尝试过:

git filter-branch --index-filter "git rm --cached --ignore-unmatch dist/bikeMap.html" HEAD
git filter-branch --index-filter "git rm --cached --ignore-unmatch dist/bikeMap.html" -- HEAD
git filter-branch -f --index-filter 'git rm --cached --quiet --force "dist/bikeMap.html"' --prune-empty -- HEAD
git filter-branch -f --index-filter 'git rm --cached --quiet --force dist/bikeMap.html' --prune-empty -- HEAD
git filter-branch -f --index-filter 'git rm --cached --quiet --force dist/bikeMap.html' --prune-empty -- master
git filter-branch -f --index-filter 'git rm --cached --quiet --force dist/bikeMap.html' --prune-empty master
git filter-branch -f --index-filter 'git rm --cached --quiet --force /dist/bikeMap.html' --prune-empty master
git filter-branch -f --index-filter 'git rm --cached --quiet --force /dist/bikeMap.html' --prune-empty HEAD

同样的错误。

编辑:进步!

git filter-branch --index-filter 'git rm --cached --quiet --force dist/bikeMap.html' --prune-empty

导致错误

Rewrite 419e8702fd8a5fe9ddad59a0fd7ff008edffdeab (1/47) (0 seconds passed, remaining 0 predicted)    
fatal: pathspec 'dist/bikeMap.html' did not match any files
index filter failed: git rm --cached --quiet --force dist/bikeMap.html

如果我 ls dist/bikeMap.html 我得到

dist/bikeMap.html

所以,它存在。

我如何使用 git filter-branch 从我们的 repo 中删除文件?

最佳答案

要使用 --tree-filter,请将 rm 命令从使用 /dist/bikeMap.html 更改为使用 dist/bikeMap.html,即删除前导斜杠。

要使用 --index-filter,请将命令更改为 git rm --cached --ignore-unmatch dist/bikeMap.html,即使用 git rm 带有额外的选项(并删除前导斜杠)。

(索引过滤器会快得多。如果你只想从所有具有该命名文件的提交中删除一个命名文件,请将索引过滤器与 git rm --cached --ignore-unmatch.)

关于git - 如何使用 git filter-branch 从我的存储库中删除文件? ("you need to run this command from the toplevel of the working tree"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52601945/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com