如何从所有的git提交中删除索引中文件的所有出现 [英] How to remove all occurences of a file in index, from all git commits
问题描述
编辑:有没有办法删除所有提交中的每个目录和文件,只保留src目录?
您可能确实希望 所以这就是rebase和filter-branch的作用:它们复制提交,并在提交之前副本,允许一些更改。然后,在提交了(略有不同的)副本后,他们将引用 - 分支和标签名称 - 移动到副本中。 记住,还有几个项目需要考虑: 现在您已准备好链接问题及其筛选器分支答案。有关使用 请注意 First time using git here. I accidentally used "git init" without a .gitignore file so I have a bunch of gradle/ and build/ files in my commits. I am using "git ls-tree -r master" to show all files in the index. Instead of checking out every single previous commit and using "git rm --cached " to remove all the unnecessary build and gradle files, how do I remove all occurences of it through all previous commits? Edit: Is there a way to remove every directory and files in all commits and only keep the src directory? You probably really do want the So this is what both rebase and filter-branch do: they copy the commits, and before committing the copy, allow some change(s). Then, having committed the (slightly different) copies, they move the references—the branch and tag names—to the copies. With that in mind, there are several more items to consider: Now you're ready for the linked question and its filter-branch answer. See this other answer to a related question as well, though, for instructions on using Note that 这篇关于如何从所有的git提交中删除索引中文件的所有出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!过滤分支
命令变基
。无论哪种方式,都需要注意以下几项:
- 标签过滤器
。 (如果你没有标签,显然这没什么关系。)而且,当过滤器分支副本签名带注释的标签时,它会删除它们的签名:它们变成无符号。否则,它将不得不让你手动重新签名它们,并且filter-branch被设计为完全自动化。
- 标记的说明,请参阅其他答案以了解相关问题
git rm -f --cached --ignore-unmatch
可用于目录(或文件夹)名称以及纯文件名。可以使用 - 树结构过滤器
(在第二个链接页面的其他答案中提及)来代替 - index-filter
,对于复杂的操作比较方便,但它比较慢(确切的放缓因操作系统,回购大小,固态硬盘与旋转介质存储等而异,但是比起使用
- index-filter
大约慢100倍是一个好的开始估计。)filter-branch
command rather than rebase
. Either way there are several items to be aware of:
--tag-filter
. (If you have no tags, this does not really matter, obviously.) And, when filter-branch copies signed annotated tags, it ditches their signatures: they become unsigned. Otherwise it would have to pester you to manually re-sign them all, and filter-branch is designed to be fully automated.--tag-name-filter
and some of the speed-up options.git rm -f --cached --ignore-unmatch
works on directory (or "folder") names as well as on plain file names. The --tree-filter
(mentioned in other answers on the second-linked page) can be used instead of the --index-filter
, and it's more convenient for complex operations, but it is much slower (exact slowdown varies based on OS, size of repo, SSD vs spinning-media storage, etc., but "about 100x slower" is a good starting estimate) than using the --index-filter
.