简体   繁体   中英

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)).

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/ )

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).

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.
Its git database is stored under .git/modules/<modulename> (instead of a .git directory under public/ ).

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)

All in all, I'm not sure if 2. or 3. are worth the effort in your situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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