25

リモートのベアリポジトリにプッシュできるように環境をセットアップしました。次のコマンドを使用して、リモートリポジトリを設定しました。

$ mkdir ~/website.git && cd ~/website.git
$ git init --bare

$ cat > hooks/post-receive

#!/bin/sh
GIT_WORK_TREE=/var/www/website git checkout -f

$ chmod +x hooks/post-receive

そして私のローカル環境で:

$ git remote add web ssh://website.com/home/website.git
$ git push web +master:refs/heads/master

これで、を使用してこのリモートにデプロイできgit push web、すべてがうまく機能します。

問題:サブモジュール

プロジェクトに、リモートリポジトリで初期化/更新されていないサブモジュールがいくつかあります。git submodule updateベアであるためにベアで実行できません。また、ファイルのコピーであり、gitリポジトリではないため、フォルダーで実行することもできません/var/www/website

4

3 に答える 3

12

私はかなりきれいに見える別の解決策を見つけました。サブモジュールを実行するために必要なすべての情報を git に与えるだけです。

$ cd /path/to/your/git_work_tree
$ git --git-dir=/path/to/your/bare_repo.git --work-tree=. submodule init
$ git --git-dir=/path/to/your/bare_repo.git --work-tree=. submodule update
于 2015-07-25T13:39:27.250 に答える
11

1つの可能な方法は次のとおりです。

言い換えれば
、ベアレポからチェックアウトしようとするのではなく、ベアレポからプルしてください。非ベアレポは、git submodule updateステップに対応できるはずです。

スクリプトの例は次のようになります

#!/bin/sh

# Get the latest code
cd /path/to/bare/repo

# Set git variables
GIT_WORK_TREE=/var/www/website
GIT_DIR=/var/www/website/.git

# Go to website and pull
cd /var/www/website
git pull /path/to/bare/repo
git submodule update --init --recursive

# Run additional build stuff here
于 2012-02-25T22:46:14.190 に答える
6

同じ問題に苦しんでいる間、私は2日前にこのスレッドに出くわしました。ようやくきちんとした解決策にたどり着いた後、私はそれについての記事をここに書きました:

サブモジュールを使用したGitプッシュ:ハウツーガイド

pushベアリポジトリにアクセスする場合は、非ベアリポジトリに使用するpost-receiveためpullだけに、シンプルにpush直接非ベアリポジトリに保存する方がよいことに気付きました。これは、ベアリポジトリにプッシュするだけの「ベストプラクティス」が複雑さを増すだけであるという明確なケースです。

リンク切れの場合は、ここに解決策を貼り付けます。あなたが行ったと確信しているのと同じ問題がすべて発生する部分をスキップします。


まず、リポジトリごとに変更する必要のないユニバーサル フックを作成しましょう。post-receive

[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

それでは、先に進んですべてのルールを破りましょう。

Webサイトディレクトリにある非ベアGitリポジトリを初期化します。から受信できることを確認してくださいgit push; 作業ツリーをその親ディレクトリに明示的に設定します。作成したフックを有効にします。

[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

神聖ながらくた、それはうまくいきました!

このメソッドはサブモジュールと互換性があるだけでなく、新しいリモートリポジトリをセットアップするために必要なコマンドは1つだけです(これは4つのコマンドで構成されています)。また、リポジトリと作業ツリーを同じ場所に保持します。また、構成ファイルやフックファイルに絶対パスが必要ないため、完全に移植可能になりました。


この回答が、過去2日間に他の人のStack Exchangeの投稿が私を助けてくれたのと同じくらい、誰かに役立つことを願っています!

于 2012-12-07T03:46:32.080 に答える