Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将git签出中的子模块包含到钩子中的git_工作树_Git_Githooks_Git Checkout - Fatal编程技术网

将git签出中的子模块包含到钩子中的git_工作树

将git签出中的子模块包含到钩子中的git_工作树,git,githooks,git-checkout,Git,Githooks,Git Checkout,在更新后挂钩中使用以下代码时,是否可以包含子模块 GIT_WORK_TREE=/path/to/directory git checkout -f 我还需要哪些其他选项来分发代码,包括来自更新后挂钩的子模块 GIT_WORK_TREE=/path/to/directory git checkout -f 谢谢。问题“”提到了一条错误消息,如果在更新后的钩子中使用此选项,您会看到: GIT_WORK_TREE=/path/to/directory git submodule update --

在更新后挂钩中使用以下代码时,是否可以包含子模块

GIT_WORK_TREE=/path/to/directory git checkout -f
我还需要哪些其他选项来分发代码,包括来自更新后挂钩的子模块

GIT_WORK_TREE=/path/to/directory git checkout -f
谢谢。

问题“”提到了一条错误消息,如果在更新后的
钩子中使用此选项,您会看到:

GIT_WORK_TREE=/path/to/directory git submodule update --init
这将产生一个:

remote: You need to run this command from the toplevel of the working tree.
因此,最好直接在目标回购中
cd
,并从那里运行命令:

export GIT_DIR=$(pwd)

cd /path/to/target/workingtree

git checkout -f master
git submodule update --init --recursive
但是,如“”所示:

运行“git子模块更新”时,似乎无法设置git_工作树

它将尝试将其用作子模块的工作树,而不是超级项目的工作树

Aaron Adams的博客文章“”描述了类似的错误消息,如中所示:

可悲的是,我怀疑这是行不通的,因为我的回购协议是一种赤裸裸的回购协议。
我在执行这些命令时遇到的错误是:


如果,为了克服上述错误,我使用如下方法:

现在让我们来打破所有的规则

我们将:

  • 初始化一个非裸Git存储库,就在我们的网站目录中
  • 确保它可以从git push接收信息
  • 显式地将其工作树设置为其父目录
  • 启用我们刚刚创建的钩子
天哪,成功了

此方法不仅与子模块兼容,还需要一个命令来设置新的远程存储库(好的,它由四个命令组成)。
它还将存储库和工作树保持在同一位置;我们的配置或钩子文件中不需要绝对路径,现在它也可以完全移植


不过:

不过,这变得有点太复杂了,所以我使用了一个简单的强制签出,并将手动更新我的子模块


也很有趣谢谢你的回复。可悲的是,这不起作用,我怀疑,因为我的回购协议是一个赤裸裸的回购协议。在执行这些命令后,我得到的错误是:
fatal:必须在工作树中运行此操作
。将“”克隆到子模块路径“”失败@iliveinapark好的,我已编辑了答案并引用了另一种方法。感谢您的贡献,VonC。不过,这变得有点太复杂了,所以我使用了一个简单的强制签出,并将手动更新我的子模块。不过,我非常感谢你的努力。
git --git-dir=<my bare repo> --work-tree=<where I export to> submodule update --init --recursive 
fatal: working tree '<where I export to>' already exists. Clone of '<submodule repo>' into submodule path '<submodule path>' failed
[aaron@aaronadams]$ cat > /usr/local/share/git-core/templates/hooks/post-receive.sample
#!/bin/sh
#
# An example hook script to update the working tree, including its
# submodules, after receiving a push.
#
# This hook requires core.worktree to be explicitly set, and
# receive.denyCurrentBranch to be set to false.
#
# To enable this hook, rename this file to "post-receive".

# Read standard input or hook will fail
while read oldrev newrev refname
do
:
done

# Unset GIT_DIR or the universe will implode
unset GIT_DIR

# Change directory to the working tree; exit on failure
cd `git config --get core.worktree` || exit

# Force checkout
git checkout --force

# Force update submodules
git submodule update --init --recursive --force
[aaron@aaronadams]$ chmod +x /usr/local/share/git-core/templates/hooks/post-receive.sample
[aaron@aaronadams]$ cd /var/www/vhosts/aaronadams.ca/sites/staging.aaronadams.ca [aaron@aaronadams]$ git init && git config --bool receive.denyCurrentBranch false && git config --path core.worktree ../ && mv .git/hooks/post-receive.sample .git/hooks/post-receive Initialized empty Git repository in /var/www/vhosts/aaronadams.ca/sites/staging.aaronadams.ca/.git/
[aaron@aaronadams]$ git remote set-url staging aaron@aaronadams.ca:sites/staging.aaronadams.ca
[aaron@aaronadams]$ git push staging master
remote: Submodule 'codeigniter' (git://github.com/EllisLab/CodeIgniter.git) registered for path 'codeigniter'
remote: Cloning into 'codeigniter'...
remote: Submodule path 'codeigniter': checked out 'fd24adf31255822d6aa9a5d2dce9010ad2ee4cf0'
To aaron@aaronadams.ca:sites/staging.aaronadams.ca
 * [new branch]      master -> master