簡體   English   中英

帶有一些子模塊的Git淺表克隆

[英]Git shallow clone with some submodules

我想獲取一些Qt模塊的源代碼。 我不需要更改歷史記錄和大多數Qt子模塊,因此我決定克隆Qt Git存儲庫並進行初始化和更新一些模塊:

git clone --branch v5.10.1 --depth 1 git://code.qt.io/qt/qt5.git source
cd source
git submodule update --init --depth 1 qtbase qtlocation

但是,當我嘗試在上面運行代碼時,出現以下錯誤:

fatal: The remote end hung up unexpectedly
Fetched in submodule path 'qtbase', but it did not contain 6c6ace9d23f90845fd424e474d38fe30f070775e. Direct fetching of that commit failed.

如果我嘗試初始化並更新所有子模塊 ,則可以使用:

git clone --branch v5.10.1 --depth 1 git://code.qt.io/qt/qt5.git source
cd source
git submodule update --init --depth 1

如何獲取git repo的源代碼,包括一些沒有版本歷史記錄的子模塊?

我正在Ubuntu 18.04中使用最新的完整版本進行類似的操作。 為此,我將ver設置為git ls-remote ,以獲取整數版本,然后升序排序並獲取最后一個。 在撰寫本文時,結果為5.12.1

ver="$(git ls-remote --heads https://code.qt.io/qt/qt5.git | grep -Pio '(?<=refs/heads/)[\d\.]+' | sort -V | tail -1)" ; git clone --depth 1 --branch $ver https://code.qt.io/qt/qt5.git

這有點復雜。 首先,我們將.gitmodules中列出的模塊組essential addon preview deprecated 從那里,我將返回到每個標題,並過濾掉不包含qtweb qtwin qtmac qtandroid qtpurch 我將遍歷列表,根據定義的分支版本對每個列表進行淺表克隆。

for value in $(grep -B10 -Pi 'status = (essential|addon|preview|deprecated)' .gitmodules | grep -Pio '(?<=\[submodule \")(?!qt(web|win|mac|android|purch)).*(?=\"\])' | sort); do git clone --depth 1 --branch $(grep -A6 -Pi "(?<=\[submodule \")$value(?=\"\])" .gitmodules | grep -Pio '(?<=\tbranch = ).*') https://code.qt.io/qt/"$value".git ; done

對我而言,最終目標是進行靜態構建,因此我只需要注意一下我使用的選項:

./configure -prefix $PWD/qtbase -static -confirm-license -opensource -ltcg -optimize-size -ccache -no-pch -skip webengine -nomake tests -nomake examples

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM