在一个GIT存储库中维持多个无关的历史

发布于 2025-01-23 12:03:33 字数 364 浏览 0 评论 0原文

我的用例:我想创建几个小示例程序,然后将它们全部存储在示例/ repo中。当某人结帐示例/a时,我希望他们能够运行git log,并且仅查看与a/的提交b/ c/ d/e/的大量无关提交。

我了解git suppodulegit subtree可以做到这一点,但是所有这些都需要单独的存储库,我认为不值得创建一个或两个文件的50个不同的存储库每个。我希望他们所有人都活在一个仓库中,但要保持不同的历史。这可能吗?

My use case: I want to create several small example programs, and store them all in an examples/ repo. When someone checkouts examples/a, I would like them to be able to run git log and see only the commits relevant to a/ without the large number of unrelated commits for b/ c/ d/ and e/.

I understand that git submodule or git subtree can do this, but those all require separate repos and I don't think it is worth creating 50 different repos of one or two files each. I would like them to all live in one repo, but maintain different histories. Is this possible?

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

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

发布评论

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

评论(1

青丝拂面 2025-01-30 12:03:33

是的,绝对。您可以在存储库中获取或创建您喜欢的任何历史记录结构。在示例中制作一个新的空分支的最简单方法

git worktree add examples/new $(git commit-tree -mstub.message `git mktree <&-`)

用您的第一组内容修改存根提交。

我还定期使用此操作来携带“合并子模型”,始终需要但与其他项目共享的实用程序代码,git subpodule命令是明显的可选,但是很容易将其用于使用此设置,只是告诉它,您已经克隆了上游模块,例如,在utils分支中带有的“ utils”历史记录,我将

git submodule init utils
git worktree add utils :utils

在克隆上,

[submodule "utils"]
    path = utils
    url = ./
    branch = utils

in in .gitmodules,这就是所有设置的机械。

Yes, absolutely. You can fetch or create any history structures you like in a repository. Easiest way to make a new empty branch in examples is

git worktree add examples/new $(git commit-tree -mstub.message `git mktree <&-`)

and amend the stub commit with your first set of content.

I also use this regularly to carry "incorporated submodules", utility code that's always required but shared with other projects, the git submodule command is distinctly optional but it's easy to finagle it into working with this setup, just tell it you've already cloned the upstream module, for e.g. a "utils" history carried in the utils branch I'll

git submodule init utils
git worktree add utils :utils

on clone, with

[submodule "utils"]
    path = utils
    url = ./
    branch = utils

in .gitmodules and that's the machinery all set up.

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