我怎样才能从git仓库中完全删除文件? [英] How can I completely remove a file from a git repository?
问题描述
git rm
不会从存储库中删除旧版本,而且我也找不到其他任何东西这看起来很有希望。您需要的工具是 git filter-branch
。其用法在这里有描述,但基本上是:
$ git filter-branch --tree-filter'rm -f my_file'HEAD
会从每个 提交中移除my_file。注意,这会重写每次提交,所以如果你推入一个远程仓库,你必须(a)强制更新,(b)从你那里拉出的其他人现在将有重复的提交(因为你重写了历史记录),如 git rebase
手册页。
I noticed recently that the project files my text editors use (along with some other junk) got added the git repository for the project. Since they aren't actually part of the project, I'd like to remove them, but git rm
doesnt remove the old versions from the repository, and I couldnt find anything else that looks promising.
The tool you want is git filter-branch
. Its usage is described here, but basically:
$ git filter-branch --tree-filter 'rm -f my_file' HEAD
will remove "my_file" from every commit.
Notice that this rewrites every commit, so if you push into a remote repository, you have to (a) force the update, and (b) everyone else who pulled from you will now have duplicate commits (since you rewrote the history), as described on the git rebase
man page.
这篇关于我怎样才能从git仓库中完全删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!