2012-05-24 14 views
13

मान लीजिए मैं अपने भंडार में दो संस्करण संदेशों प्रतिबद्ध शामिल करें ... प्रत्येक इस प्रकार के रूप में चिह्नित किया गया है:submodule के साथ "Git लॉग"

  • tag1
  • TAG2

अब मान लें कि एक प्रतिबद्ध ने टैग 1 और टैग 2 के बीच एक नई सबमिशन प्रतिबद्धता को इंगित करने के लिए एक सबमिशन संदर्भ अपडेट किया। मैं निम्न आदेश चलाता हूं, और इसे प्राप्त करता हूं:

# 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. 

इस मामले में, केवल परिवर्तन ही सबमिशन का एक अद्यतन था। मैं सबमिशन को माता-पिता के भंडार के साथ अंतःस्थापित करने के लिए कैसे प्राप्त करूं?

विशेष रूप से, इस उदाहरण में, मान लीजिए कि अभिभावक भंडार सबड्यूल 5 में सबटाग 5 टैग को इंगित करता है। सबमिशन में बाद में दो काम करता है एक SubTag6 टैग है। प्रतिबद्धता ने SubTag5 के बजाय SubTag6 को इंगित करने के लिए सबमिशन पॉइंटर को अद्यतन किया। मैं क्या करना चाहता हूं git log है, जो पहले से ही मुद्रित किए गए प्रतिबद्धता के अतिरिक्त है, दो सबमिशन मॉड्यूल प्रिंट करें, साथ ही SubTag5 से सबटाग 6 तक सबमिशन लाया।

उत्तर

6

आप सबमिशन परिवर्तन प्रदर्शित कर सकते हैं, लेकिन केवल git log -p का उपयोग करते समय। निम्न आदेश प्रत्येक प्रतिबद्धता और सबमिशन परिवर्तनों का पूर्ण अंतर दिखाता है।

git log -p --submodule=log 

submodule प्रतिबद्ध संदेशों इस तरह सूचीबद्ध किया जाएगा:

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

कार्यात्मक की क्रमबद्ध करें, लेकिन वहाँ एक तरह से मुख्य भंडार के समान submodules के लिए एक अधिक स्वच्छ उत्पादन प्राप्त करने के लिए है, पूर्ण diff से जूझने के बिना ? उदाहरण के लिए, गिट लॉग मुख्य भंडार पर लेखक और दिनांक और पूर्ण प्रतिबद्ध संदेश प्रिंट करता है। किसी भी पैच diffs के साथ, मुख्य भंडार में प्रतिबद्धता के नीचे सूचीबद्ध submodules के लिए ऐसी प्रविष्टियां अच्छा लगेगा। –

+0

जहां तक ​​मुझे पता है कि अब रास्ता है। लेकिन आप अभी भी आउटपुट पर कुछ नियमित अभिव्यक्तियां चला सकते हैं, जो उन सभी सामानों को फ़िल्टर करते हैं जिन्हें आप देखना नहीं चाहते हैं। – iblue

0

आप Windows पर काम कर रहे हैं, तो आप इस 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 "" 
      } 
     } 
    } 
} 

जाहिर है यह अनुवाद किया जा सकता लिनक्स पर उपयोग के लिए बाश करने के लिए।

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 के समान) के लिए प्रतिबद्ध एक सरल बैश आदेश interleaves प्रासंगिक submodule करता है जब एक submodule superproject में बदल जाती है है: सामान्य सिद्धांत यह है। यह प्रत्येक प्रतिबद्धता के लिए पूर्ण पैच प्रिंट करता है और फिर केवल सारांश पंक्तियों और सबमिशन परिवर्तनों को छोड़कर पैच सामग्री को फ़िल्टर करने के लिए 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

यह गिटक में यह शानदार होगा! –

संबंधित मुद्दे