简体   繁体   English

git 恢复子模块 - 子模块目录已创建但为空

[英]git restore submodules - submodule directory created but empty

When pushing to production the submodules are not updated.推送到生产时,子模块不会更新。 The submodule root directory is created but no files inside子模块根目录已创建,但里面没有文件

post-receive接收后

#/bin/sh
cd /var/www/repo
git --work-tree=. --git-dir=/var/git_repos/repo.git checkout master -f
git --work-tree=. --git-dir=/var/git_repos/repo.git git submodule update --init --recursive

When browsing through github the submodules are present and linked with latest version浏览 github 时,子模块存在并与最新版本链接

When I run git push production master from remote I get this当我从远程运行git push production master时,我得到了这个

# git push production master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 284 bytes | 284.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Already on 'master'
remote: git: 'git' is not a git command. See 'git --help'.
remote:
remote: The most similar command is
remote:         init
To ssh://domain.com/var/git_repos/repo.git
   a710c83..6d75702  master -> master

As I mentioned in our discussion , I would first use git submodule update , because it will:正如我在讨论中提到的,我将首先使用git submodule update ,因为它会:

  • update the registered submodules to match what the superproject expects by cloning missing submodules,通过克隆丢失的子模块来更新注册的子模块以匹配超级项目的期望,
  • fetch missing commits in submodules and获取子模块中丢失的提交和
  • update the working tree of the submodules.更新子模块的工作树。

The second point "fetch missing commits in submodules" is the missing step which triggers, when you push to your base repo, the error message第二点“获取子模块中缺少的提交”是缺少的步骤,当您推送到基本仓库时,会触发错误消息

remote: fatal: failed to unpack tree object d09a53c53a7bd222df4869e66b9e45acee45e094
remote: error: Submodule 'php/repo/utils' could not be updated.

So try with the script:所以尝试使用脚本:

#/bin/sh
cd /var/www/repo
git --work-tree=. --git-dir=/var/git_repos/repo.git checkout master -f
git --work-tree=. --git-dir=/var/git_repos/repo.git submodule update --remote
                                                  ^^^^
                                                (no git there)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM