70

Git 1.7.0の新しいスパース チェックアウト機能を使用すると、SVN のようにサブディレクトリの内容を取得することは可能ですか? この例を見つけましたが、完全なディレクトリ構造が保持されています。「perl」という名前の実際のディレクトリなしで、「perl」ディレクトリの内容だけが欲しかったと想像してください。

- 編集 -

例:

私のgitリポジトリには次のパスが含まれています

repo/.git/
repo/perl/
repo/perl/script1.pl
repo/perl/script2.pl
repo/images/
repo/images/image1.jpg
repo/images/image2.jpg
repo/doc/
repo/doc/readme.txt
repo/doc/help.txt

私が欲しいのは、上記のリポジトリからこのレイアウトを生成できるようにすることです:

repo/.git/
repo/script1.pl
repo/script2.pl

ただし、現在のスパース チェックアウト機能では、取得のみが可能のようです。

repo/.git/
repo/perl/script1.pl
repo/perl/script2.pl

これは私が望むものではありません。

4

7 に答える 7

27

すべてのファイルを含むリポジトリ全体を複製する必要があります。フラグを使用して--depth、限られた量の履歴のみを取得できます。

リポジトリのクローンが作成されると、read-tree トリックによって、リポジトリの「ビュー」がファイル内のファイルまたはディレクトリのみに制限され.git/info/sparse-checkoutます。

現時点では少し不親切なので、まばらさを管理するのに役立つ簡単なスクリプトを作成しました。

#!/bin/sh
echo > .git/info/sparse-checkout
for i in "$@"
do
    echo "$i" >> .git/info/sparse-checkout
done
git read-tree -m -u HEAD

このスクリプトをgit-sparse.shを呼び出して報告されたパスに保存するとgit --exec-path、実行git sparse foo/ bar/して foo および bar ディレクトリのみを「チェックアウト」するかgit sparse '*'、すべてを元に戻すことができます。

于 2010-02-26T10:23:29.820 に答える
16

短い答えはノーです。Git はすべてのファイルを 1 つの単位として認識します。

私がお勧めするのは、リポジトリを論理的なチャンクに分割することです。perl、画像、およびドキュメント用の別のもの。uber リポジトリ スタイルも維持する必要がある場合は、 Submodules で構成されるリポジトリを作成できます

于 2010-03-16T22:58:27.137 に答える
6

richq の答えは近いものでしたが、ステップを逃しました。スパース チェックアウトを明示的に有効にする必要があります。

git config core.sparsecheckout true

このブログ投稿には、すべての手順が明確に概説されています。

http://blog.quilitz.de/2010/03/checkout-sub-directories-in-git-sparse-checkouts/comment-page-1/#comment-3146

于 2012-01-07T23:00:05.020 に答える
5

なぜこれを行う必要があるのか​​ について詳しく説明することなく、問題は(おそらく)シンボリックリンク/ショートカットによって簡単に解決できます。

To answer the question - no, and with a meaningful reason. The whole history of the repo is downloaded even with a 'sparse checkout'. To clarify why this is necessary - otherwise tracking renamed files would be a pain in the ...neck. Imagine you move the file /repo_root/asd/file1.cpp to /repo_root/fgh/file1.cpp - now if you had only downloaded /repo_root/fgh deltas, you won't know about file1.cpp. So this means you must download all deltas. But then you have a full repository; not just a folder cut of it, therefore just the /rero_root/fgh folder is not a repo itself. This might not sound important when you checkout, but when you commit, git might not know enough to work alright.

Workaround: If you really want to, you can create a script that calls git-checkout in such a manner (for the sh shell, batch for windows should not be hard to produce):

!/bin/sh
curDir=`pwd`
cd $2
git-checkout $1
cp -R $3/* $4
cd $curDir

Here the first argument is the branch to checkout, the second - the folder where the repo is currently present, the third - the subdir you want to really use, and the fourth - the location to which you want it copied.

Warning: my shell skills are almost non-existent, so use this after testing. It should not be hard to recreate the reverse of this script, that copies back stuff, so that it can be committed to the repo.

于 2011-08-07T01:10:42.450 に答える
3

git filter-branch --subdirectory-filterDetach (move) subdirectory into separate Git repository を参照してください。

これを行うための小さな bash スクリプトを次に示します。

これにより、最初に元のリポジトリの作業コピーが作成され、次にサブディレクトリ フィルターを使用してブランチがフィルター処理され、必要なものが得られます。

#!/bin/bash
#
# git-subdir.sh
#
git clone --no-hardlinks $1 $2

cd $2

git filter-branch --subdirectory-filter $2 --prune-empty --tag-name-filter cat HEAD -- --all

git reset --hard

git remote rm origin

refbak=$(git for-each-ref --format="%(refname)" refs/original/)

if [ -n "$refbak" ];then
    echo -n $refbak | xargs -n 1 git update-ref -d
fi

git reflog expire --expire=now --all

git repack -ad

git gc --aggressive --prune=now

質問の例に使用するgit-subdir.sh repo perlとうまくいきます。

于 2012-03-01T05:09:49.203 に答える
2

三つ編みを試すことができます-パスに一致させながらリモートを追跡します。 https://github.com/evilchelu/braid/wiki

于 2010-12-30T23:04:56.367 に答える
0

ファイルが別の場所に配置されるように、ディレクトリ ツリーの名前を変更しようとしているようです。あなたが求めているのは、モジュールの分類(Javaノードの下のJavaビット、Perlノードの下のPerl)、および異なる場所にファイルを持つプロジェクトを持つという2つの点で、コード/プロジェクト管理のアンチテンプレートであるように思われます開発者がそれらを視覚化する場所から。git はディレクトリ コンテンツのハッシュを維持して変更内容を確認するため、これにより git 自体が壊れます。

デーモン・レイデル

于 2015-03-05T19:29:05.833 に答える