如何在 Git 中永久删除文件而不出现“警告:Ref 'refs/heads/master' 未更改”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9240949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove a file permanently in Git without getting "WARNING: Ref 'refs/heads/master' is unchanged"?
提问by Tower
I have been googling and reading various posts around the net and I've tried:
我一直在谷歌搜索和阅读网上的各种帖子,我试过:
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch Launcher\lib" --prune-empty -- --all
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch Launcher\lib" --prune-empty -- --all
and
和
git filter-branch --tree-filter "rm -rf Launcher\lib" --prune-empty -- --all
git filter-branch --tree-filter "rm -rf Launcher\lib" --prune-empty -- --all
All resulting in a:
所有结果为:
WARNING: Ref 'refs/heads/master' is unchanged
警告:Ref 'refs/heads/master' 不变
There are other clones of this repository and a central server also. I will push changes to the server, as I understand, others with clones just need to fetch and rebase (not merge)? Would it still work if they have made changes?
该存储库还有其他克隆版本和中央服务器。我会将更改推送到服务器,据我所知,其他拥有克隆的人只需要获取和变基(而不是合并)?如果他们进行了更改,它仍然有效吗?
回答by Tower
Okay I solved the problem, it was the path that was wrong. I changed this:
好的,我解决了问题,是路径错误。我改变了这个:
Launcher\lib
Launcher\lib
to this:
对此:
Launcher/lib/
Launcher/lib/
and now it works ;)
现在它起作用了;)
回答by Yar
I'm gonna put this here as a future reference since I had the same problem:
If you use cmder
(or other ConEmu
flavors), use double quotes instead of single quotes.
我将把它放在这里作为将来的参考,因为我遇到了同样的问题:如果你使用cmder
(或其他ConEmu
风格),请使用双引号而不是单引号。
Also wrap the path in quotes if you have some white space in your address:
如果您的地址中有一些空格,还要将路径用引号括起来:
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch 'server/bin/some file.txt'" \
--prune-empty --tag-name-filter cat -- --all
That was the problem when I got that error.
当我遇到那个错误时,这就是问题所在。