简体   繁体   English

如何删除git子模块内的提交历史?

[英]How to delete history of commits inside a git submodule?

I have a git project (with source files = markdown files published with hugo) with a submodule (linked to a "public/" folder, and containing only some generated files (that are then published to github pages through a dedicated github project)).我有一个带有子模块(链接到“public/”文件夹,并且只包含一些生成的文件(然后通过专用 github 项目发布到 github 页面))的 git 项目(源文件 = 用 Hugo 发布的 markdown 文件)) .

HOME : 
  .git/
  .gitmodules
  content/
  public/ -> linked to a submodule (no .git folder)

Submodule has been added through git submodule add -b slides <URL> public (per : https://gohugo.io/hosting-and-deployment/hosting-on-github/ )子模块已通过git submodule add -b slides <URL> public (每: https : //gohugo.io/hosting-and-deployment/hosting-on-github/

Everything is working fine (i can commit and push source files and/or auto-generated files separately).一切正常(我可以分别提交和推送源文件和/或自动生成的文件)。

But i have a growing commit history for the content of the submodule folder (published in a dedicated project).但是我对子模块文件夹(在专用项目中发布)的内容有越来越多的提交历史记录。 Moreover this is 100% useless (being autogenerated all the time).此外,这是 100% 无用的(一直自动生成)。

So is there a way to easily remove all these commits from the submodule, and only from it ?那么有没有一种方法可以轻松地从子模块中删除所有这些提交,并且只能从它中删除?

The submodule is a local clone of the target repo.子模块目标 repo 的本地克隆。
Its git database is stored under .git/modules/<modulename> (instead of a .git directory under public/ ).它的 git 数据库存储在.git/modules/<modulename> (而不是public/下的.git目录)。

So :所以 :

  1. the short answer is : "no there is no easy way"简短的回答是:“不,没有简单的方法”
  2. if you want to keep it as a submodule : you can try to create a specific branch in the base repo, which would only keep some selected commits from the main branch如果你想把它作为一个子模块:你可以尝试在基础仓库中创建一个特定的分支,它只会保留来自主分支的一些选定的提交
  3. if you can afford to drop the dependency as a submodule : you may look into other ways to integrate this external repo ( git subtree for example)如果您有能力将依赖项作为子模块删除:您可以研究其他方法来集成此外部存储库(例如git subtree

All in all, I'm not sure if 2. or 3. are worth the effort in your situation.总而言之,我不确定 2. 或 3. 在您的情况下是否值得付出努力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM