如何从 git 历史记录中删除不再存在的文件?

发布于 2025-01-19 11:58:59 字数 382 浏览 1 评论 0原文

几个月前,我们已经从SVN转换为Git(Bitbucket),现在我们正在收到警告,警告我们的GIT存储库正在向大型库(目前为2.2GB)。但是,当我检查本地大小时,我们的项目的大小仅为 +-600MB。这是一个已经开发了6年以上的项目,因此有许多提交(历史记录),尤其是诸如.jar viles之类的文件,而不是返回删除以替换为新版本等。它们在我们的上不存在当前的项目不再存在了,但是它们仍然处于GIT历史上,它们占用了不需要的空间,因为我们再也不会使用它们,我正在寻找一种方法来删除所有不存在的删除文件当前的项目并将其完全从GIT提交历史记录中删除(并非所有已删除的文件)。我知道有“ git-filter”命令可以从提交记录中删除文件,但据我所知,您必须指定要删除的wich文件,而我不知道有多少 / wich文件在上面删除了。我们项目的几年。

We have changed from SVN to GIT ( bitbucket ) a few months ago, now we are recieving a warning that our git repository is becomming to large ( currently at 2.2GB ). However when i check the local size our project is only +- 600MB in size. This is a project that has been in development for over 6 years so there are many commits ( history ) especially files like .jar viles that got added, and than back deleted to be replaced with newer versions etc. They don't exist on our current project anymore, but they are still in the git history where they take up space that isn't needed because we won't ever use them again, i'm looking for a way to remove all deleted files that don't exist in the current project and remove them completely from the git commit history ( not all files that ever got deleted ). I know that there is the 'git-filter' command to remove a file from the commit history but as far as i can see you have to specify wich file to be remove while i have no idea how many / wich files got deleted over the years in our project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

善良天后 2025-01-26 11:58:59

您可以使用命令 git filter-branch

git filter-branch --index-filter \
    'git rm -rf --cached --ignore-unmatch path_to_file' HEAD

请小心,因为您将改写您的存款历史记录

You can use the command git filter-branch

git filter-branch --index-filter \
    'git rm -rf --cached --ignore-unmatch path_to_file' HEAD

Be careful because you will rewrite the history of your deposit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文