简体   繁体   English

如何在 git 存储库中使用“人工根提交”?

[英]How to work with an "artificial root commit" in a git repository?

Problem and Motivation问题和动机

We have a larger git repository on our central server.我们的中央服务器上有一个更大的 git 存储库。 There is a lot of history in it that we want to keep, so rebasing or squashing anything there is not really an option.其中有很多我们想要保留的历史,因此重新定位或压缩任何东西都不是真正的选择。 However, when cloning the repository to our development servers, only recent history is actually relevant.但是,将存储库克隆到我们的开发服务器时,实际上只有最近的历史记录是相关的。 For us, "recent" can be defined as a given tag and any commit earlier in the history can be omitted.对我们来说,“最近”可以定义为给定的标签,并且可以省略历史中较早的任何提交。 The aim here is to save bandwidth, time and disk space.这里的目的是节省带宽、时间和磁盘空间。

Ideas for Approach方法的想法

The current idea is to clone that tag only, using git clone --branch my-root-tag --depth 1 , treating it as an artificial root commit in that local repository.当前的想法是仅克隆该标签,使用git clone --branch my-root-tag --depth 1 ,将其视为该本地存储库中的人工根提交。 Afterwards, adding branches that we'd like to fetch manually using git remote set-branches --add origin some-branch .之后,使用git remote set-branches --add origin some-branch添加我们想要手动获取git remote set-branches --add origin some-branch All of these branches must include my-root-tag somewhere in their history.所有这些分支都必须在其历史记录中的某处包含my-root-tag However, every fetch would now again transfer the entire history.但是,现在每次获取都会再次传输整个历史记录。 Is there any way to restrict fetches to stop at my-root-tag instead?有什么方法可以限制提取停止在my-root-tag吗? It sounds like this approach would need something like asked in git shallow clone since specific commit , ideally wrapped in a git alias to "dynamically" calculate the value of the --depth parameter.听起来这种方法需要类似于在git浅克隆中提出的问题, 因为特定的提交,理想情况下包装在 git 别名中以“动态”计算--depth参数的值。

Can anyone think of a way to get this to work or even by applying some entirely different approach?任何人都可以想出一种方法来让它发挥作用,甚至可以应用一些完全不同的方法吗?

Results结果

edit: To summarize, it seems that a git fetch does indeed only transfer the commits up to the grafted new repository root (at least in Git v 2.25.1).编辑:总而言之,似乎git fetch确实只将提交传输到嫁接的新存储库根目录(至少在 Git v 2.25.1 中)。 Only the original clone needs to be parameterized correctly, while subsequent operations on the repository can be performed using regular (unparameterized) git commands.只有原始clone需要正确参数化,而对存储库的后续操作可以使用常规(未参数化)git 命令执行。 No shallow-include or shallow-exclude options are actually necessary now.现在实际上不需要shallow-includeshallow-exclude选项。 This is great news as it makes that configuration a lot less fragile than initially feared.这是个好消息,因为它使该配置不像最初担心的那样脆弱。

It seems that fetching everything up to a commit is what should happen using --shallow-exclude=my-root-tag See How to maintain shallow clone of a set of branches in git似乎使用--shallow-exclude=my-root-tag所有内容提取到提交应该发生什么,请参阅如何在 git 中维护一组分支的浅层克隆

This similar question suggests using --shallow-since=<date of tagged commit> : Git: Shallow copies from a specific commit这个类似的问题建议使用--shallow-since=<date of tagged commit> : Git: Shallow --shallow-since=<date of tagged commit> from a specific commit

Also related:还相关:

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

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