git git子模块跟踪最新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9189575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:55:48  来源:igfitidea点击:

git submodule tracking latest

gitgit-submodulesgit-track

提问by l.thee.a

We are moving our (huge) project to git and we are thinking about using submodules. Our plan is to have three different heads in the superproject: release,stable,latest. The project leads will handle the release and stable branches. They will move the submodules as required.

我们正在将我们的(巨大的)项目转移到 git 并且我们正在考虑使用子模块。我们的计划是在超级项目中拥有三个不同的头:发布、稳定、最新。项目负责人将处理发布和稳定分支。他们将根据需要移动子模块。

The issue is the "latest" head. We would like the superproject "latest" head to track the master branches of all the submodules (automatically). And also it would be great if it would show the history of all commits to the submodule.

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

I have looked at gitslave, but it is not quite what we want. Any suggestions?

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

回答by VonC

Update March 2013

2013 年 3 月更新

Git 1.8.2added the possibility to track branches.

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

" git submodule" 开始学习一种新模式来与远程分支的提示集成(而不是与记录在超级项目的 gitlink 中的提交集成)。

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

# update your submodule
git submodule update --remote 

If you had a submodule already presentyou now wish would track a branch, see "how to make an existing submodule track a branch".

如果您已经有一个子模块您现在希望跟踪分支,请参阅“如何使现有子模块跟踪分支”。

Also see Vogella's tutorial on submodulesfor general information on submodules.

有关子模块的一般信息,另请参阅Vogella 的子模块教程

Note:

笔记:

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

See git submoduleman page:

请参阅git submodule手册页

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.

一个特殊的值.用于指示子模块中分支的名称应与当前存储库中的当前分支名称相同



See commit b928922727d6691a3bdc28160f93f25712c565f6:

提交 b928922727d6691a3bdc28160f93f25712c565f6

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

submodule add: 如果--branch给出,记录在.gitmodules

This allows you to easily record a submodule.<name>.branchoption in .gitmoduleswhen you add a new submodule. With this patch,

这使您submodule.<name>.branch可以在.gitmodules添加新子模块时轻松记录选项。有了这个补丁,

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

Signed-off-by: W. Trevor King

将从您用于初始化子模块的同一分支获取更新,这通常是您想要的。

签字人:W. Trevor King



Original answer (February 2012):

原始答案(2012 年 2 月):

A submodule is a single commit referenced by a parent repo.
Since it is a Git repo on its own, the "history of all commits" is accessible through a git logwithin that submodule.

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

So for a parent to track automatically the latest commit of a given branch of a submodule, it would need to:

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

  • cd in the submodule
  • git fetch/pull to make sure it has the latest commits on the right branch
  • cd back in the parent repo
  • add and commit in order to record the new commit of the submodule.
  • 子模块中的 cd
  • git fetch/pull 以确保它在正确的分支上有最新的提交
  • cd 回到父仓库
  • 添加和提交以记录子模块的新提交。

gitslave(that you already looked at) seems to be the best fit, including for the commit operation.

gitslave(您已经看过)似乎是最合适的,包括提交操作

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

由于需要检出到正确的子模块分支,进行更改,提交,然后进入超级项目并提交提交(或至少记录子模块的新位置),因此对子模块进行更改有点烦人子模块)。

Other alternatives are detailed here.

此处详细介绍了其他替代方案。