- bounty将在7天后过期**。回答此问题可获得+50的声誉奖励。Charlie Parker正在寻找此问题的更详细的答案。
理想情况下,我希望.modules
文件包含我想使用的提交,并且不修改它(除非我告诉它,例如git submodule --init <path2submodule_repo> --remote
).但是git子模块add注解似乎没有提供选项(所以我假设. gitmodules不能这样做?)例如,参见手册页:
NAME
git-submodule - Initialize, update or inspect submodules
SYNOPSIS
git submodule [--quiet] [--cached]
git submodule [--quiet] add [<options>] [--] <repository> [<path>]
git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
git submodule [--quiet] init [--] [<path>...]
git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>...)
git submodule [--quiet] update [<options>] [--] [<path>...]
git submodule [--quiet] set-branch [<options>] [--] <path>
git submodule [--quiet] set-url [--] <path> <newurl>
git submodule [--quiet] summary [<options>] [--] [<path>...]
git submodule [--quiet] foreach [--recursive] <command>
git submodule [--quiet] sync [--recursive] [--] [<path>...]
git submodule [--quiet] absorbgitdirs [--] [<path>...]
DESCRIPTION
Inspects, updates and manages submodules.
For more information about submodules, see gitsubmodules(7).
COMMANDS
With no arguments, shows the status of existing submodules. Several subcommands are available to perform operations on the submodules.
add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
Add the given repository as a submodule at the given path to the changeset to be committed next to the current project: the current
project is termed the "superproject".
<repository> is the URL of the new submodule’s origin repository. This may be either an absolute URL, or (if it begins with ./ or ../),
the location relative to the superproject’s default remote repository (Please note that to specify a repository foo.git which is located
right next to a superproject bar.git, you’ll have to use ../foo.git instead of ./foo.git - as one might expect when following the rules
for relative URLs - because the evaluation of relative URLs in Git is identical to that of relative directories).
The default remote is the remote of the remote-tracking branch of the current branch. If no such remote-tracking branch exists or the
HEAD is detached, "origin" is assumed to be the default remote. If the superproject doesn’t have a default remote configured the
superproject is its own authoritative upstream and the current working directory is used instead.
The optional argument <path> is the relative location for the cloned submodule to exist in the superproject. If <path> is not given, the
canonical part of the source repository is used ("repo" for "/path/to/repo.git" and "foo" for "host.xz:foo/.git"). If <path> exists and
is already a valid Git repository, then it is staged for commit without cloning. The <path> is also used as the submodule’s logical name
in its configuration entries unless --name is used to specify a logical name.
The given URL is recorded into .gitmodules for use by subsequent users cloning the superproject. If the URL is given relative to the
superproject’s repository, the presumption is the superproject and submodule repositories will be kept together in the same relative
location, and only the superproject’s URL needs to be provided. git-submodule will correctly locate the submodule using the relative URL
in .gitmodules.
这是在bash脚本中手动记录提交的唯一方法,如下所示:
git submodule add -f --name coq-projects/metalib https://github.com/plclub/metalib.git coq-projects/metalib
git submodule foreach -q --recursive 'git switch $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master || echo main )'
但显然经过了编辑,因此它可以与提交一起工作?例如。
git submodule add -f --name coq-projects/metalib https://github.com/plclub/metalib.git coq-projects/metalib
Run git submodule foreach git checkout <commit-hash> to change the checked-out commit in each submodule to the desired commit. Replace <commit-hash> with the hash of the desired commit.
1条答案
按热度按时间2q5ifsrm1#
Git子模块是在Git repo下跟踪的,所以它包含了在其中处理Git子项目提交的过程。只需进入Submodule目录, checkout 到任何你想要的分离提交、修订或标记,然后再次转到主repo根目录并执行Git diff,它会显示Submodule的提交哈希diff;用这样的描述来提交:“将X的子项目提交更新为标记Y”。
在此之后,当您想要克隆存储库时,您将使用recurse-submodules标志进行递归克隆。
然后,在克隆时,按以下方式克隆:
希望有帮助。