git 将特定文件推送到另一个远程

发布于 2025-01-15 05:05:13 字数 522 浏览 5 评论 0原文

我有一个 git 存储库,其中包含几个链接的项目,就像

|-- configs
|   |-- A.py
|   `-- B.py
|-- datasets
|   |-- a.py
|   |-- b.py
|   `-- c.py
|-- models
|   |-- x.py
|   `-- y.py
`-- projects
    |-- A.py
    |-- B.py
    `-- common.py

我想使用新的遥控器发布这些文件的子集。从阅读文档来看,这似乎是不可能的。您会建议什么替代方案? 我正在考虑:

  • 复制粘贴到新的存储库(但如果代码在一侧更新,我将不会从另一侧的更改中受益,
  • 将整个存储库推送到新的远程(但我不确定我想分享一切)
  • 重构存储库并使用子模块或 git 子树(但是对于公共文件来说它变得很复杂,这意味着创建 3 个存储库(每个项目一个 + 一个用于公共事物,维护起来很麻烦,尤其是对于非常几个文件)

任何关于如何解决这个问题的建议?

I have a git repository containing several linked projects like

|-- configs
|   |-- A.py
|   `-- B.py
|-- datasets
|   |-- a.py
|   |-- b.py
|   `-- c.py
|-- models
|   |-- x.py
|   `-- y.py
`-- projects
    |-- A.py
    |-- B.py
    `-- common.py

I would like to publish a subset of those files with a new remote. From reading the documentation, it's seems not possible. What alternative would you suggest?
I'm thinking of:

  • copy-pasting to a new repository (but if code is updated on one side, I won't benefit from the changes on the other side
  • pushing the whole repository to the new remote (but I'm not sure I want to share everything)
  • Restructuring repo and use submodules or git subtree (but it gets complicated for the common files, that would mean creating 3 repositories (one for each project + one for common things, which is messy to maintain, especially for very few files)

Any advice on how to address this problem?

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

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

发布评论

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

评论(1

江心雾 2025-01-22 05:05:13

Git 管理提交。每个提交都关联一个文件树,其中包含所有文件的列表。该文件树是提交哈希的一部分,也是存储库完整性的关键部分。因此,Git 无法推送文件的子集,因为这意味着必须更改提交。 Git 子树是一种常用工具,用于维护两条历史记录,一条供外部使用,可以限制为目录的子集,另一条供内部使用。

正如您提到的,您有多种选择。复制,这违背了源代码控制系统的使用,推送整个存储库或使用 git 子模块或 git 子树来生成可以共享的较小存储库。我可以推荐 git subtree,因为它非常容易管理,并且可以轻松地将文件从更改的上游合并回来。

Git manages commits. Each commit associates a file tree, containing the list of all files. This file tree is part of the commit hash, and a key part to the integrity of the repository. As a result, Git cannot push a subset of files, as it would mean having to change commits. Git subtree is a common tool to maintain two history lines, one for external use that can be restricted to a subset of directories, and the internal one.

You have various options, as you mentioned. Copying, which defies the use of the source control system, pushing the whole repository or using either git submodules or git subtrees to produce a smaller repository that you can share. I can recommend git subtree as it is quite easy to manage and can easily merge files back from a changed upstream.

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