title: Git: How can I find a commit that most closely matches a directory?
body: <p>Someone took a version (unknown to me) of Moodle, applied many changes within a directory, and released it (<a href="https://github.com/mrclay/moodle-rubric-1.9/tree/5ed4c9409f76a250fb56d74a527fe7894a676c5c/mod/assignment" rel="noreferrer">tree here</a>).</p>
  
  <p><strong>How can I determine which commit of the original project was most likely edited to form this tree?</strong></p>
  
  <p>this would allow me to form a branch at the appropriate commit with this patch. Surely it came from either the <a href="https://github.com/moodle/moodle/tree/MOODLE_18_STABLE/mod/assignment" rel="noreferrer">1.8</a> or <a href="https://github.com/moodle/moodle/tree/MOODLE_19_STABLE/mod/assignment" rel="noreferrer">1.9</a> branches, probably from a release tag, but diffing between particular commits doesn't help me much.</p>
  
  <p><strong>Postmortem Update:</strong> <a href="https://stackoverflow.com/questions/6388283/git-how-can-i-find-a-commit-that-most-closely-matches-a-directory/6388694#6388694">knittl's answer</a> got me as close as I'm going to get. I first added my patch repo as the remote "foreign" (no commits in common, that's OK), then did diffs in loops with a couple format options. The first used the <code>--shortstat</code> format:</p>
  
  <pre><code>for REV in $(git rev-list v1.9.0^..v1.9.5); do 
      git diff --shortstat "$REV" f7f7ad53c8839b8ea4e7 -- mod/assignment &gt;&gt; ~/rdiffs.txt; 
      echo "$REV" &gt;&gt; ~/rdiffs.txt; 
  done;
  </code></pre>
  
  <p>The second just counted the line changes in a unified diff with no context:</p>
  
  <pre><code>for REV in $(git rev-list v1.9.0^..v1.9.5); do 
      git diff -U0 "$REV" f7f7ad53c8839b8ea4e7 -- mod/assignment | wc -l &gt;&gt; ~/rdiffs2.txt;
      echo "$REV" &gt;&gt; ~/rdiffs2.txt; 
  done;
  </code></pre>
  
  <p>There were thousands of commits to dig through, but <a href="https://github.com/moodle/moodle/commit/b54847edc3e213e280dc8e0f0648be2c13bf35f2" rel="noreferrer">this one</a> seems to be the closest match.</p>