7

ローカルコミットを実行できるようにするために、いくつかの作業にgit-svnを使用し始めました。これは、標準のsvnレイアウトを使用するプロジェクトに最適です。最近、接続された複数のモジュール(20〜25)に分割されたJavaプロジェクトの作業を開始しました。各モジュールには、同じsvnリポジトリ内に独自のトランク/ブランチ/タグを持つ独自のルートフォルダーがあります。

svnrepo/    
  module-1
    trunk
    branches
    tags
  module-N
    trunk
    branches
    tags

git svn clone -s / path / to / svnrepo /module[1-N]を使用してすべてのモジュールのクローンを作成しました。「問題」は、すべてのモジュールでgit svn rebaseを実行したい場合、N回実行する必要があることです。

git svn clone / path / to / svnrepo /を実行しようとしましたが、リベース操作をN回実行しないようにしましたが、svnリポジトリと同じディレクトリレイアウトが残ります。

1つのgitリポジトリですべてのモジュールのすべてのトランクを追跡できる方法はありますか?gitリポジトリ内に次のようなディレクトリレイアウトを取得するには、次のようにします。

module-1
module-2
module-N
4

2 に答える 2

2

残念ながら、いいえ、これを行う方法はありません。1つの問題は、2つ以上のモジュールが同じ名前のブランチを持つことを妨げるものが何もないということです。次に、git-svnでブランチ名を付けると、どのモジュールについて話しているのかをどのように知ることができますか?

この問題は、Subversionではブランチがファーストクラスの概念ではないのに対し、gitではファーストクラスの概念であるという事実に実際に起因しています。git-svnは、多かれ少なかれクラッジを使用してこの事実を回避できますが、レポが「非標準」レイアウト(使用しているレイアウトなど)の場合、クラッジは機能しなくなります。

git-svn rebase私の提案:それらすべてにスクリプトを書いてください。

于 2009-05-22T18:41:26.360 に答える
0

私はあなたと同じ問題に直面していることに気づき、これを行うための標準的な方法がないことに気づきました。しかし、周りを見回して、これを行うための戦略を見つけ、それに基づいてPowerShellスクリプトを作成しました。ソースを思い出せない、または私は彼らに信用を与えるでしょう。説明しますが、台本とコメントだけが見やすいです。

このスクリプトを使用することも、Windows / PowerShellを使用していない場合は、それに基づいて作成することもできます。良い点は、サブモジュールごとに個別のgitリポジトリを作成したら、何かが失敗した場合に、新しい「マスター」gitリポジトリを削除し、スクリプトに変更を加えて、スクリプトを再実行するだけです。ローカル。

サブモジュールに別のサブモジュールと同じと呼ばれるフォルダがある場合など、処理されない場合があることに注意してください(したがって、BINというサブモジュールがあり、他のサブモジュールにBINサブフォルダがある場合、失敗します)。また、開始する前に、すべてのサブモジュールのgitリポジトリが最新であることを確認してください。

この要点でスクリプトを確認できます: 要点スクリプト

なんらかの理由で要点がわからなくなった場合は、ここにも追加しました(読みにくくなりますが)

$GitReposLocation = "path\to\individual\git\repos"; #1 git repo for each module (you svn cloned each one using std layout)
$MasterGitRepoLocation = "path\to\masterRepo"; #the path where you want your main repo that contains all the modules
git reset --hard;

write-host Creating folder $MasterGitRepoLocation -foregroundcolor "green";
mkdir $MasterGitRepoLocation;

write-host Moving to folder $MasterGitRepoLocation -foregroundcolor "green";
cd $MasterGitRepoLocation;

write-host Creating Git Repository -foregroundcolor "cyan";
git init;

#this is hacky, but we need to have an initial commit
"" > root;
git add root;
write-host Creating root node -foregroundcolor "cyan";
git commit -m "Initial commit to create parent root.";

#we are going to be moving files around, and don't want to move the files we already got in our MasterRepo root/workspace
$NotMoveThesFiles = @();
dir |%{$NotMoveThesFiles+=@($_.FullName) };

$repos = @();
# you should add a repo here if for some reasong you don't want to process that one.
# $repos+=@("SomeRepo");

dir -Path $GitReposLocation -Directory |Where-object{ $repos -NotContains $_.Name }|%{$repos+=@($_.Name) };

# for-each repo....
$repos|%{ 
        $SubRepoName = $_;
        write-host Processing GitRepo $SubRepoName -foregroundcolor "green";        
        $Remote = "remote"+$SubRepoName;        

        #add this git repo (of a module) as a remote of our main repo
        write-host Adding reference to $SubRepoName as remote repo -foregroundcolor  "cyan";
        git remote add -f $Remote $GitReposLocation\$SubRepoName;

        #Merge that sub repo into the main repo. The only problem? It will copy that repo's workspace
        #directly into our main repo Root folder
        write-host Merging remote$SubRepoName/master into master -foregroundcolor  "cyan";
        git merge remote$SubRepoName/master;

        #so now we are going to create a folder with  the name of this module (subRepo)
        #and move everything that is in the Master's root folder to that folder, except of course
        #things that we already had in the root folder before the merge. (in the NotMoveTheseFiles array)

        write-host Moving files got from $SubRepoName to a subdir called $SubRepoName -foregroundcolor  "green";

        #create folder folr the module
        mkdir $SubRepoName;
        #add these new folde to the list of things we don't want to move into it.
        $NotMoveThesFiles+=@($SubRepoName);

        #copy all files not in the NotMoveTheseFiles array into the newly created folder.
        dir |where-object {$NotMoveThesFiles -NotContains $_} |%{git mv $_ $SubRepoName};

        #commit the change where we moved all these files around.
        $CommitMessage = "Moving files got from " + $SubRepoName + " to a subdir called $SubRepoName"
        git commit -m $CommitMessage;
    }
于 2014-03-22T02:04:18.090 に答える