如何减少.git/对象的大小?

发布于 2025-02-13 05:50:34 字数 441 浏览 1 评论 0原文

我的.git目录过于大,让我不高兴。过去,我添加并添加了一些装满大型二进制文件的目录。随后,我将它们从最新的主人中删除,但它们仍然存储在历史中。我永远不需要它们。我的主要目的是减小.git目录的大小,并尽可能少。

  1. 我可以从整个回购历史记录中清除特定目录,当然可能会导致可能的依赖性地震(在这种情况下不是因为这些文件没有依赖性,而是用于将来参考)

  2. ?在特定提交之前。我没有理由从第一天起就保留该项目的整个历史,如果这样做,我可以将其放在一个叉子中,我永远不会与主要仓库同步

  3. 2个子集,我可以清除整个整个回购除了最近的提交吗?

如果另一个开发人员获取/合并以上方式屠杀的回购,会发生什么?

我知道手动做所有上述所有操作的方法,但我很懒惰,想要一种简单,轻松的方法来使用尽可能少的命令来完成上述操作。

谢谢

My .git directory is overly large and displeasing me. I have, in the past, added and committed some directories that were full of large binary files. I've subsequently removed them from the latest master, but they are still stored in the history. I will never need them. My primary intent is to reduce the size of the .git directory, with as few side effects as possible.

  1. Can I purge particular directories from the entire repo history, of course potentially causing possible dependency earthquakes (not in this case as these files have no dependents but for future reference)

  2. Can I completely remove all history prior to a particular commit. I have no reason to keep the entire history of this project from day one, and if I did, I could just put it in a fork that I never sync with the main repo

  3. A subset of 2, can I purge the entire repo except for the most recent commit?

What happens if another developer fetch/merges a repo which has been butchered in the above ways?

I know of manual ways to do all of the above but I am lazy and want an easy, git way to do the above with as few commands as possible.

Thanks

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

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

发布评论

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

评论(1

终难愈 2025-02-20 05:50:34
  1. 是:请参阅,例如,如何从git存储库中的提交历史记录中删除/删除/删除一个大文件?((为 joanis注释

  2. 是。考虑使用 git replace repent在历史截止点,替代提交的 no 父母,

      git替换-graft< commit-hash>
     

    (请注意我们如何列出新父母。)嫁接到位后,请使用不推荐的git filter-branch或fancy new new git filter-repo命令像以前一样“巩固移植物”。在这里完全不需要任何过滤器来表示“空过滤器”。参见,例如,如何从git存储库中的提交历史记录中删除/删除大文件?

  3. 是:这是特别容易做到的git clone检查您选择的分支,这是该分支上的最新提交 - 只需运行rm -rf .git .git(或任何本地操作系统的等效内容)在将工作树留在适当的位置时,要销毁存储库。然后运行git Init创建一个新的空存储库,运行git add。添加整个工作树,然后运行git commit创建第一个也是唯一的提交(如果需要,然后将分支重命名)。

  1. Yes: see, e.g., How to remove/delete a large file from commit history in the Git repository? (as joanis notes in a comment).

  2. Yes. Consider using git replace to make a substitute commit at the history cut-off point, where the substitute commit has no parents, with:

    git replace --graft <commit-hash>
    

    (Note how we list no new parents.) Once the graft is in place, use the deprecated git filter-branch or the fancy new git filter-repo command to "cement the graft into place", as it were. The "empty filter" represented by using no filters at all suffices here. See, e.g., the filter-branch related answers to How to remove/delete a large file from commit history in the Git repository?

  3. Yes: this one is particularly easy to do since you can just clone the original repository, check out the desired commit—this may not require any work since git clone checks out the branch of your choice, which is the latest commit on that branch—and simply run rm -rf .git (or whatever your local OS's equivalent is) to destroy the repository while leaving the working tree in place. Then run git init to create a new, empty repository, run git add . to add the entire working tree, and run git commit to create the first and only commit (and then rename the branch if desired).

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