2017-09-30 28 views
0

この問題を再現するためのテストbashスクリプトは、git --versionは "git version 1.9.1"です。基本的に、私は、「ソース親プロジェクト」/tmp/TestMainレポにサブモジュールとして使用「ソースサブモジュール」レポ/tmp/TestSubberを、持っている - と私は/tmp/TestLocMainとして、クローンに「ローカル」クローンを作成するソースは、サブモジュールを初期化します。git detached headが原因で 'git submodule update'が失敗しました 'fatal:1つのリビジョンが必要'

set -x 

rm -rfv /tmp/TestSubber /tmp/TestMain /tmp/TestLocMain 
mkdir /tmp/TestSubber /tmp/TestMain 
cd /tmp/TestSubber; git init; 
git config user.name me; git config user.name [email protected]; 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 01' 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 02' 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 03' 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 04' 
git checkout HEAD~2 
git status # HEAD detached at f221985 

cd /tmp/TestMain; git init; 
git config user.name me; git config user.name [email protected]; 
echo "bbbb" >> b.txt ; git add b.txt; git commit -m 'commit 01' 
git submodule add -b master --depth 1 -- https://github.com/rtyley/small-test-repo TestSubber 
git add -u; git commit -m 'added submodule' 

cd /tmp 
git clone file:///tmp/TestMain /tmp/TestLocMain 
cd TestLocMain 
sed -i"" 's!https://github.com/rtyley/small-test-repo!file:///tmp/TestSubber!g' .gitmodules 
git submodule sync 
git submodule update --init --remote --depth 1 --merge -- TestSubber 

このスクリプトを実行すると、git submodule updateとの最後のステップはで失敗します:

... 
+ git submodule update --init --remote --depth 1 --merge -- TestSubber 
Submodule 'TestSubber' (file:///tmp/TestSubber) registered for path 'TestSubber' 
Cloning into 'TestSubber'... 
remote: Counting objects: 3, done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Receiving objects: 100% (3/3), done. 
Checking connectivity... done. 
From file:///tmp/TestSubber 
* branch   HEAD  -> FETCH_HEAD 
fatal: Needed a single revision 
Unable to find current origin/master revision in submodule path 'TestSubber' 

は一見問題がデタッチHEAD状態でそのレポを強制的に元のサブモジュールレポ/tmp/TestSubber、中git checkout HEAD~2です。

... 
+ git submodule update --init --remote --depth 1 --merge -- TestSubber 
Submodule 'TestSubber' (file:///tmp/TestSubber) registered for path 'TestSubber' 
Cloning into 'TestSubber'... 
remote: Counting objects: 3, done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Receiving objects: 100% (3/3), done. 
Checking connectivity... done. 
Submodule path 'TestSubber': checked out 'ad110f4932339fe5efb940608139b08a28b8c518' 

は今、私の実際のユースケースは何 TestSubberに対応することは巨大であるということで、当面はデタッチHEAD状態のままにする必要があります:あなたが行 git checkout HEAD~2コメント場合、最終的な段階ではと成功します。サブモジュールの更新を TestLocMainに強制的に完了させるには、 TestSubberの状態を変更せずに何かできますか?

答えて

0

まあ、私はそれを得たように見えます - 基本的には、一つは、裸のレポとして/tmp/TestLocMain/.git/modules/TestSubberを再構築するために、次にGitがGIT_DIRとしてそれを引っ張るか、とGIT_WORK_TREEなど/tmp/TestLocMain/TestSubber、そして最終的には今んgit submodule update...コマンドを(発行必要--mergeなどは必要ありません)。なお、git submodule update...コマンドも完全チェックアウトを実行するかどうかをテストするために、世代を追加して100MBのファイルを追加しました(明らかにそうではありません)。

set -x 

rm -rfv /tmp/TestSubber /tmp/TestMain /tmp/TestLocMain 
mkdir /tmp/TestSubber /tmp/TestMain 
cd /tmp/TestSubber; git init; 
git config user.name me; git config user.name [email protected]; 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 01' 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 02' 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 03' 
echo "aaaa" >> a.txt ; git add a.txt; git commit -m 'commit 04' 
dd if=/dev/urandom of=big.file bs=1M count=100 
git add big.file; git commit -m 'commit 05 big.file' 
git checkout HEAD~2 
git status # HEAD detached at f221985 

cd /tmp/TestMain; git init; 
git config user.name me; git config user.name [email protected]; 
echo "bbbb" >> b.txt ; git add b.txt; git commit -m 'commit 01' 
git submodule add -b master --depth 1 -- https://github.com/rtyley/small-test-repo TestSubber 
git add -u; git commit -m 'added submodule' 

cd /tmp 
git clone file:///tmp/TestMain /tmp/TestLocMain 
cd TestLocMain 
sed -i"" 's!https://github.com/rtyley/small-test-repo!file:///tmp/TestSubber!g' .gitmodules 
git submodule sync 
mkdir -p .git/modules/TestSubber 
MODDIR="`cd .git/modules/TestSubber && pwd`" 
GIT_DIR="$MODDIR" git init --bare 
GIT_DIR="$MODDIR" git config core.bare false 
GIT_DIR="$MODDIR" git remote add origin file:///tmp/TestSubber 
cd /tmp/TestLocMain 
echo 'gitdir: ../.git/modules/TestSubber' > TestSubber/.git 
GIT_DIR="$MODDIR" GIT_WORK_TREE="/tmp/TestLocMain/TestSubber" git pull --depth=1 origin master 

git submodule update --init --remote --depth 1 -- TestSubber 
git submodule status 
関連する問題