最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Git Submodule Add with --branch specific --depth 1 Fails - Stack Overflow

programmeradmin0浏览0评论

I'm trying to add a Git submodule to my project using the git submodule add command with specific options. However, I'm encountering an error during the checkout phase that suggests the specified branch isn't being recognized correctly.

Command Executed:

GIT_TRACE=true git submodule add -b branch_1.1.0 --depth 1 https://oauth2:****@gitlab.test.ir/repo.git path

Git Trace Output:

41407 git.c:742               trace: exec: git-submodule add -b branch_1.1.0 --depth 1 https://oauth2:****@gitlab.test.ir/repo.git path
13:47:05.641530 run-command.c:668       trace: run_command: git-submodule add -b branch_1.1.0 --depth 1 https://oauth2:****@gitlab.test.ir/repo.git path
13:47:05.679587 git.c:455               trace: built-in: git rev-parse --git-dir
13:47:05.684522 git.c:455               trace: built-in: git rev-parse --git-path objects
13:47:05.690491 git.c:455               trace: built-in: git rev-parse --show-prefix
13:47:05.693754 git.c:455               trace: built-in: git rev-parse --show-toplevel
13:47:05.700485 git.c:455               trace: built-in: git submodule--helper add --branch branch_1.1.0 --depth=1 -- https://oauth2:****@gitlab.test.ir/repo.git path
13:47:05.700910 run-command.c:668       trace: run_command: git add --dry-run --ignore-missing --no-warn-embedded-repo path
13:47:05.704795 run-command.c:668       trace: run_command: unset GIT_PREFIX; GIT_DIR=.git git clone --no-checkout --depth 1 --separate-git-dir /tmp/partServiceCreditEvaluation/.git/modules/path -- https://oauth2:****@gitlab.test.ir/repo.git /tmp/partServiceCreditEvaluation/path
13:47:05.706850 git.c:455               trace: built-in: git clone --no-checkout --depth 1 --separate-git-dir /tmp/repo/.git/modules/path -- https://oauth2:****@gitlab.test.ir/repo.git /tmp/repo/path
Cloning into '/tmp/repo/path'...
13:47:05.710148 run-command.c:668       trace: run_command: git remote-https origin https://oauth2:****@gitlab.test.ir/repo.git
13:47:05.712268 git.c:742               trace: exec: git-remote-https origin https://oauth2:****@gitlab.test.ir/repo.git
13:47:05.712334 run-command.c:668       trace: run_command: git-remote-https origin https://oauth2:****@gitlab.test.ir/repo.git
13:47:06.012442 run-command.c:668       trace: run_command: 'git credential-store store'
13:47:06.014892 git.c:455               trace: built-in: git credential-store store
13:47:10.681842 run-command.c:668       trace: run_command: git --shallow-file /tmp/repo/.git/modules/path/shallow.lock index-pack --stdin -v --fix-thin '--keep=fetch-pack 3620169 on W-P0-DVP1950'
remote: Enumerating objects: 63, done.
remote: Counting objects: 100% (63/63), done.
remote: Compressing objects: 100% (55/55), done.
13:47:10.686985 git.c:455               trace: built-in: git index-pack --stdin -v --fix-thin '--keep=fetch-pack 3620169 on W-P0-DVP1950'
remote: Total 63 (delta 5), reused 34 (delta 2), pack-reused 0 (from 0)
Receiving objects: 100% (63/63), 30.68 MiB | 699.00 KiB/s, done.
Resolving deltas: 100% (5/5), done.
13:47:55.750966 run-command.c:668       trace: run_command: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
13:47:55.752479 git.c:455               trace: built-in: git rev-list --objects --stdin --not --all --quiet --alternate-refs '--progress=Checking connectivity'
13:47:55.755585 run-command.c:668       trace: run_command: cd path; unset GIT_PREFIX; GIT_DIR=.git git checkout -f -q -B branch_1.1.0 origin/branch_1.1.0
13:47:55.757695 git.c:455               trace: built-in: git checkout -f -q -B branch_1.1.0 origin/branch_1.1.0
fatal: 'origin/branch_1.1.0' is not a commit and a branch 'branch_1.1.0' cannot be created from it
fatal: unable to checkout submodule 'path'

Problem Description: When executing the above command, I expect Git to add the submodule using the specified branch branch_1.1.0 with a shallow clone (--depth 1). However, during the checkout phase, Git attempts to create and checkout the branch branch_1.1.0 from origin/branch_1.1.0, resulting in the following error:

fatal: 'origin/branch_1.1.0' is not a commit and a branch 'branch_1.1.0' cannot be created from it
fatal: unable to checkout submodule 'path'

Why isn't Git correctly applying the --branch flag when performing the clone operation?

    13:47:05.706850 git.c:455               trace: built-in: git clone --no-checkout --depth 1 --separate-git-dir /tmp/partServiceCreditEvaluation/.git/modules/path -- https://oauth2:****@gitlab.test.ir/repo.git /tmp/partServiceCreditEvaluation/path
Cloning into '/tmp/repo/path'...
发布评论

评论列表(0)

  1. 暂无评论