gpt4 book ai didi

git子模块跟踪最新

转载 作者:IT王子 更新时间:2023-10-29 01:21:07 25 4
gpt4 key购买 nike

我们正在将我们的(巨大的)项目移动到 git,并且我们正在考虑使用子模块。我们的计划是在 super 项目中拥有三个不同的负责人:

release, stable, latest

项目负责人将处理发布和稳定分支。他们将根据需要移动子模块。

问题是“最新”的头。我们希望 super 项目“最新”负责人跟踪所有子模块的主分支(自动)。如果它能显示子模块的所有提交历史,那就太好了。

我看过gitslave,但不是我们想要的。有什么建议吗?

最佳答案

编辑(2020.12.28):自 2020 年 10 月起,GitHub 将默认的 ma​​ster 分支更改为 ma​​in 分支。参见 https://github.com/github/renaming
下面的这个答案仍然反射(reflect)了旧的命名约定。


2013 年 3 月更新

Git 1.8.2添加了跟踪分支的可能性。

"git submodule" started learning a new mode to integrate with the tip of the remote branch (as opposed to integrating with the commit recorded in the superproject's gitlink).

# add submodule to track master branch
git submodule add -b master [URL to Git repo];

# update your submodule
git submodule update --remote

如果您有一个子模块已经存在,您现在希望跟踪一个分支,请参阅“ how to make an existing submodule track a branch ”。

另见 Vogella's tutorial on submodules有关子模块的一般信息。

注意:

git submodule add -b . [URL to Git repo];
^^^

参见 git submodule man page :

A special value of . is used to indicate that the name of the branch in the submodule should be the same name as the current branch in the current repository.


参见 commit b928922727d6691a3bdc28160f93f25712c565f6 :

submodule add: If --branch is given, record it in .gitmodules

Signed-off-by: W. Trevor King

This allows you to easily record a submodule.<name>.branch option in .gitmodules when you add a new submodule. With this patch,

$ git submodule add -b <branch> <repository> [<path>]
$ git config -f .gitmodules submodule.<path>.branch <branch>

reduces to

$ git submodule add -b <branch> <repository> [<path>]

This means that future calls to

$ git submodule update --remote ...

will get updates from the same branch that you used to initialize the submodule, which is usually what you want.


原始答案(2012 年 2 月):

子模块是由父仓库引用的单个提交。
由于它本身就是一个 Git 存储库,因此可以通过 git log 访问“所有提交的历史记录”。在该子模块中。

因此,要让父级自动跟踪子模块给定分支的最新提交,它需要:

  • 进入子模块
  • git fetch/pull 以确保它在正确的分支上有最新的提交
  • cd 回到父仓库
  • 添加并提交以记录子模块的新提交。

gitslave (你已经看过了)似乎是最合适的,including for the commit operation .

It is a little annoying to make changes to the submodule due to the requirement to check out onto the correct submodule branch, make the change, commit, and then go into the superproject and commit the commit (or at least record the new location of the submodule).

其他选择是 detailed here .

关于git子模块跟踪最新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9189575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com