В идеале я хотел бы, чтобы в файле .modules
была точная фиксация, которую я хочу использовать, и не менялась (если я не скажу, например, с помощью git submodule --init <path2submodule_repo> --remote
). Но комментарий добавления подмодуля git, похоже, не предоставляет опции (поэтому я предполагаю, что .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.
Но это работает, если вы git добавите его (в любом случае, я полагаю, с нашим без коммита в URL-адресе, так как он все равно получит неправильный) cd и выберите правильный коммит:
(iit_synthesis) brando9~/proverbot9001 $ git submodule add -f --name coq-projects/metalib git+https://github.com/plclub/metalib.git#104fd9efbfd048b7df25dbac7b971f41e8e67897 coq-projects/metalib
Reactivating local git directory for submodule 'coq-projects/metalib'.
...
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ cd coq-projects/metalib
-bash: cd: coq-projects/metalib: No such file or directory
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ git checkout 104fd9efbfd048b7df25dbac7b971f41e8e67897
Note: switching to '104fd9efbfd048b7df25dbac7b971f41e8e67897'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 104fd9e Sync Makefile coq version with README/Docker
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ git status
HEAD detached at 104fd9e
nothing to commit, working tree clean
Подмодуль Git отслеживается в репозитории Git, поэтому он состоит из обработки в нем коммита подпроекта Git. Просто войдите в каталог Submodule, извлеките любую отсоединенную фиксацию, ревизию или тег, который вы хотите, и снова перейдите в основной корень репо и выполните Git diff, он покажет вам разницу хэшей фиксации для Submodule; зафиксируйте это с описанием вроде: «Обновите фиксацию подпроекта для X, чтобы пометить Y».
После этого, когда вы захотите клонировать репозиторий, вы будете клонировать рекурсивно с флагом recurse-submodules.
cd <Submodule path>
git checkout <hash/tag/branch/etc>
cd -
git status
git add <Submodule>
git commit "Update Subproject Commit for X to tag Y"
git push
Затем при клонировании клонируйте таким образом:
git clone --recurse-submodules <my repo with Submodules>
Надеюсь, поможет.
Чтобы сделать ответ Даниэля конкретным, это работает:
# -- Get metalib foor coq-8.10 via commit when getting it through git submodules
## git init the right metalib if it wasn't git submodule init properly. ref: https://stackoverflow.com/questions/74757297/how-do-i-make-sure-to-re-add-a-submodule-correctly-with-a-git-command-without-ma, ref2: https://github.com/UCSD-PL/proverbot9001/issues/59, ref3: https://github.com/UCSD-PL/proverbot9001/issues/60
#rm -rf coq-projects/metalib
#git submodule add -f --name coq-projects/metalib https://github.com/plclub/metalib.git coq-projects/metalib
git submodule add -f --name coq-projects/metalib git+https://github.com/plclub/metalib.git#104fd9efbfd048b7df25dbac7b971f41e8e67897 coq-projects/metalib
git submodule update --init coq-projects/metalib
# cd to coq-projects/metalib and make sure it's using the hash 104fd9efbfd048b7df25dbac7b971f41e8e67897
(cd coq-projects/metalib && git checkout 104fd9efbfd048b7df25dbac7b971f41e8e67897)
(git status && cd ..)
приблизительный вывод:
(iit_synthesis) brando9~/proverbot9001 $ rm -rf coq-projects/metalib
(iit_synthesis) brando9~/proverbot9001 $
(iit_synthesis) brando9~/proverbot9001 $ git submodule add -f --name coq-projects/metalib git+https://github.com/plclub/metalib.git#104fd9efbfd048b7df25dbac7b971f41e8e67897 coq-projects/metalib
Reactivating local git directory for submodule 'coq-projects/metalib'.
(iit_synthesis) brando9~/proverbot9001 $
(iit_synthesis) brando9~/proverbot9001 $ cd metalib
-bash: cd: metalib: No such file or directory
(iit_synthesis) brando9~/proverbot9001 $ cd coq-projects/
(iit_synthesis) brando9~/proverbot9001/coq-projects $ cd metalib
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ git rev-parse HEAD
4ea92d82286cf66e54b4119b2bb2b039827204ab
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ cd coq-projects/metalib
-bash: cd: coq-projects/metalib: No such file or directory
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ git checkout 104fd9efbfd048b7df25dbac7b971f41e8e67897
Note: switching to '104fd9efbfd048b7df25dbac7b971f41e8e67897'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 104fd9e Sync Makefile coq version with README/Docker
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ git status
HEAD detached at 104fd9e
nothing to commit, working tree clean
по теме: https://github.com/UCSD-PL/proverbot9001/issues/82 по теме: https://github.com/UCSD-PL/proverbot9001/issues/86
счастлив вознаградить любого, кто заставляет git submodule add -f --name coq-projects/metalib git+https://github.com/plclub/metalib.git#104fd9efbfd048b7df25dbac7b971f41e8e67897 coq-projects/metalib
работать.
У меня нет прав на запись в репозиторий git. Так что не могу толкнуть. Но я думаю, что могу cd и проверить нужную мне ветку. Кстати, указание коммита в добавлении подмодуля git на удивление не работает ... обновит вопрос, чтобы отразить это.