2012-05-24 13 views
13

でコミットメッセージサブモジュール含めますコミットは、サブモジュール参照をTag1とTag2の間の新しいサブモジュールコミットを指すように更新しました。私は次のコマンドを実行し、これを得る:は、私は次のようにそれぞれがタグ付けされた私のリポジトリ内に2つのバージョンが...持っていると仮定「gitのログ」

# show commits between these two tags 
git log Tag1..Tag2 


commit be3d0357b93322f472e8f03285cb3e1e0592eabd 
Author: James Johnston <snip> 
Date: Wed Jan 25 19:42:56 2012 +0000 

    Updated submodule references. 

この場合、唯一の変更はサブモジュールの更新であった。親リポジトリがコミットするサブモジュールコミットをインターリーブする方法を教えてください。

具体的には、この例では、親リポジトリがサブモジュール内のSubTag5タグを指しているとします。サブモジュールの後の2つのコミットはSubTag6タグです。示されたコミットはSubTag5ではなくSubTag6を指すサブモジュールポインタを更新しました。私がしたいのはgit logです。それは既に印刷されているコミットに加えて、SubTag5からSubTag6にサブモジュールを持ってきた2つのサブモジュールコミットも印刷します。

答えて

6

git log -pを使用している場合のみ、サブモジュールの変更を表示することができます。次のコマンドは、各コミットとサブモジュールの完全な差分を示します。

git log -p --submodule=log 

サブモジュールコミットメッセージは次のように表示されます:あなたがWindows上で作業している場合

Submodule <submodule-name> <starting-commit>..<ending-commit>: 
> Commit message 1 
> Commit message 2 
... 
> Commit message n 
+1

ソートが、メインリポジトリに似たサブモジュールのための非常にクリーンな出力を取得する方法は、完全な差分を通じてウェーディングせずに、そこにあります?たとえば、git logは、メインリポジトリに作成者と日付と完全コミットメッセージを表示します。メインリポジトリのコミットの下にリストされたサブモジュールのようなエントリを、パッチの差分はなくていいといいでしょう。 –

+0

私が知る限り、今や道があります。しかし、あなたはまだ出力にいくつかの正規表現を実行することができます。 – iblue

0

は、あなたがこのPowerShellスクリプトを使用することができます明らかに

function Parse-SubmoduleDiff($rawDiffLines) { 
    $prefix = "Subproject commit " 
    $oldCommitLine = $($rawDiffLines | where { $_.StartsWith("-" + $prefix) } | select -First 1) 
    $newCommitLine = $($rawDiffLines | where { $_.StartsWith("+" + $prefix) } | select -First 1) 

    if ($newCommitLine -eq $null) { 
     return $null 
    } 

    $oldCommit = $null 
    if ($oldCommitLine -ne $null) { 
     $oldCommit = $oldCommitLine.Substring($prefix.Length + 1) 
    } 
    $newCommit = $newCommitLine.Substring($prefix.Length + 1) 
    return @{ OldCommit = $oldCommit; NewCommit = $newCommit } 
} 

# Get the paths of all submodules 
$submodulePaths = $(git submodule foreach --quiet 'echo $path') 
if ($submodulePaths -eq $null) { 
    $submodulePaths = @() 
} 

# Get the log of the parent repository (only SHA1) 
$log = $(git log --format="%H %P" $args) 
foreach ($line in $log) { 

    $parts = $line.Split() 
    $commit = $parts[0] 
    $parents = $parts[1..$parts.Length] 

    # Print the summary for this commit 
    git show --format=medium --no-patch $commit 
    echo "" 

    # Can be more than one parent if it's a merge 
    foreach ($parent in $parents) { 
     # List the paths that changed in this commit 
     $changes = $(git diff --name-only $parent $commit) 

     if ([System.String]::IsNullOrWhiteSpace($parent)) { 
      continue; 
     } 

     foreach ($path in $changes) { 

      if ($submodulePaths.Contains($path)) { 
       # if it's a submodule, the diff should look like this: 
       # -Subproject commit 1486adc5c0c37ad3fa2f2e373e125f4000e4235f 
       # +Subproject commit a208e767afd0a51c961654d3693893bbb4605902 
       # from that we can extract the old and new submodule reference 

       $subDiff = $(git diff $parent $commit -- $path) 
       $parsed = Parse-SubmoduleDiff($subDiff) 
       if ($parsed -eq $null) { 
        continue; 
       } 

       # Now get the log between the old and new submodule commit 
       $oldCommit = $parsed.OldCommit 
       $newCommit = $parsed.NewCommit 
       echo "Submodule '$path'" 
       if ($oldCommit -ne $null) { 
        $range = $($oldCommit + ".." + $newCommit) 
       } else { 
        $range = $newCommit 
       } 

       git --git-dir $path/.git log $range | foreach { " | " + $_ } 
       echo "" 
      } 
     } 
    } 
} 

を、それを翻訳することができますLinuxでの使用のためにbashする一般的な原則はこれです:

for each commit in the parent repo 
    print the commit summary 
    for each submodule that has changed in this commit 
     get the old and new commit hashes of the submodule 
     print the log of the submodule between those commits 
    end for 
end for 
9

ここでASCIIがサブモジュールは親プロジェクトに変更された場合、関連するサブモジュールがコミットするインターリーブ(gitkに似ている)のグラフをコミット作成し、簡単なbashコマンドです。コミットごとに完全なパッチを出力し、grepを使用してパッチの内容をフィルタリングして、要約行とサブモジュールの変更だけを残します。

git log --graph --oneline -U0 --submodule Tag1..Tag2 | grep -E '^[*| /\\]+([0-9a-f]{7} |Submodule |> |$)' 

それは、このような出力生成:機能の

* 854407e Update submodule 
| Submodule SUB 8ebf7c8..521fc49: 
| > Commit C 
* 99df57c Commit B 
* 79e4075 Commit A 
+0

これをgitkに入れるのはすばらしいことです! –

関連する問題