ifi*_*iht 16 git github git-submodules
我有一个带有多个子模块的 git repo。我尝试删除和添加有问题的子模块(scopatz 的 nanorc),但是在删除和重新添加过程中错误仍然存在。当我将 repo 克隆到一个新位置时,我会自动使用 更新它git submodule update --init --recursive,这是失败时,但仅适用于此子模块......以下是命令的相关输出GIT_TRACE=2:
23:01:26.918691 run-command.c:1569 run_processes_parallel: preparing to run up to 1 tasks
23:01:26.933567 run-command.c:1601 run_processes_parallel: done
23:01:26.934373 run-command.c:646 trace: run_command: git gc --auto
23:01:26.966805 git.c:344 trace: built-in: git gc --auto
23:01:26.991059 git.c:344 trace: built-in: git rev-parse --local-env-vars
23:01:27.015684 git.c:344 trace: built-in: git rev-parse --local-env-vars
23:01:27.032282 git.c:344 trace: built-in: git symbolic-ref -q HEAD
23:01:27.053948 git.c:344 trace: built-in: git config --get branch.master.remote
23:01:27.073636 git.c:344 trace: built-in: git fetch origin 151d94a8754b0a612315fc191c5373cc0055c13d
23:01:27.079657 run-command.c:646 trace: run_command: git-remote-https origin https://github.com/scopatz/nanorc.git
23:01:28.441725 run-command.c:646 trace: run_command: git rev-list --objects --stdin --not --all --quiet
23:01:28.452267 run-command.c:646 trace: run_command: git fetch-pack --stateless-rpc --stdin --lock-pack --thin https://github.com/scopatz/nanorc.git/
23:01:28.467757 git.c:344 trace: built-in: git fetch-pack --stateless-rpc --stdin --lock-pack --thin https://github.com/scopatz/nanorc.git/
fatal: remote error: upload-pack: not our ref 151d94a8754b0a612315fc191c5373cc0055c13d
fatal: The remote end hung up unexpectedly
Fetched in submodule path 'submodules/nano', but it did not contain 151d94a8754b0a612315fc191c5373cc0055c13d. Direct fetching of that commit failed.
Run Code Online (Sandbox Code Playgroud)
希望这里有人可以提供帮助,此时我几乎迷失了方向。
=== 编辑:下面的解决方案步骤 ===
cd {submodule path}
git reset --hard origin/master
cd -
git clean -n
git add {submodule path}
git commit
git submodule update --init --recursive
Run Code Online (Sandbox Code Playgroud)
没有错误,很棒。
如果您没有完全提交本地更改并将其推送到子模块,则可能会发生这种情况。
我在使用子模块克隆我们的存储库之一时遇到此错误,而原始的本地存储库工作正常。问题是因为我忘记推送子模块更改。
因此,请确保提交并推送所有子模块更改。
使用 Git 和子模块,您可以从至少两个 Git 存储库开始。一个是“你的”存储库——主存储库,Git 将其称为superproject。第二个 Git 存储库是其他一些 Git 存储库:它没有什么特别之处。只是你的超级项目中有这两部分:
克隆子模块的说明。这可以让您的 Gitgit clone在需要时运行,git submodule update --init例如在运行期间。
应该在其他 Git 存储库中的某个提交的原始哈希 ID 。在克隆或git fetch在其他 Git 存储库的克隆中适当运行后,您的主存储库将使用此原始哈希 ID运行。git checkout hash
您的超级项目要求提供151d94a8754b0a612315fc191c5373cc0055c13dGit 存储库中的哈希 ID ,您可以从https://github.com/scopatz/nanorc.git克隆。该提交根本不存在于该存储库中,因此它也不存在于您制作的任何克隆中。
你知道为什么你的超级项目会列出这个提交哈希 ID,即使它不存在吗?(我当然没有。)你不能从他们的 Git 中得到它,因为他们没有。这就是所有这些错误消息告诉你的。
您可以尝试搜索其他存储库(或 Google)151d94a8754b0a612315fc191c5373cc0055c13d(我刚刚尝试使用 Google,但他们找不到)。或者,如果你并不特别关心那个提交,试着告诉你自己的 Git——你的超级项目——它应该得到一些其他的提交,一个确实存在,因此你可以得到。
你应该得到哪个提交?我不知道:这取决于你。请注意,这个地方在那里你上层项目列出了从原料子模块提交哈希是:在每次提交。你可以git checkout在你的超级项目中提交一些提交,可能是某个分支的提示。然后你可以进入子模块,选择你喜欢的提交,git checkout在该子模块中使用——毕竟它是另一个 Git 克隆,所以你可以在那里执行任何 Git 命令——以检查所需的提交。然后,退出子模块(将目录更改回您的超级项目)并git add在子模块路径上运行并git commit记录新的所需哈希 ID。这种新的承诺,现在询问的是特定的哈希ID。
git submodule update --remote
Run Code Online (Sandbox Code Playgroud)
然后
git commit && git push
Run Code Online (Sandbox Code Playgroud)
一切都会变好
| 归档时间: |
|
| 查看次数: |
8886 次 |
| 最近记录: |