title: How to troubleshoot an abnormally slow git-diff?
body: <p>I recently cloned a remote repo in which some <code>git</code> commands run extremely slowly.  For example, running</p>
  
  <pre><code>git diff --quiet
  </code></pre>
  
  <p>...takes ~40 s.  (For what it's worth, the repo is clean.  I am using <code>git</code> version 2.20.1.)</p>
  
  <p>While trying to figure out what's causing this sluggishness, I have bumped into a handful of procedures that abolish it, though I have no idea why.</p>
  
  <p>Of these procedures, the simplest/quickest one I've found is this: (starting from a freshly-cloned instance of the repo) create a branch off <code>master</code>, and checkout it out.  After this, if I check out <code>master</code> once more, now <code>git diff --quiet</code> finishes quickly (under 50ms).</p>
  
  <p>Below is an example interaction, showing timing information for the various opertions<sup>1</sup>:</p>
  
  <pre><code>rm -rf ./"$REPONAME"      #  0.174 s
  git clone "$URL"          # 54.118 s
  cd ./"$REPONAME"          #  0.007 s
  
  git diff --quiet          # 39.438 s
  
  git branch VOODOO         #  0.032 s
  git checkout VOODOO       # 31.247 s
  git diff --quiet          #  0.014 s
  
  git checkout master       #  0.034 s
  git diff --quiet          #  0.012 s
  </code></pre>
  
  <p>As I've already stressed, this is only one of several possible procedures that "fix" the repo, and they are all equally mysterious to me.  This only happens to be the simplest/quickest one I've found.</p>
  
  <p>The above sequence of timings is very reproducible (i.e. I get roughly the same timings every time I run that specific sequence exactly as shown).</p>
  
  <p>It is, however, <em>very</em> sensitive to seemingly small variations.  For example if I replace the <code>git branch VOODOO; git checkout VOODOO</code> with <code>git checkout -b VOODOO</code>, the subsequent profile of timings changes radically:</p>
  
  <pre><code>rm -rf ./"$REPONAME"      #  0.015 s
  git clone "$URL"          # 45.312 s
  cd ./"$REPONAME"          #  0.007 s
  
  git diff --quiet          # 46.145 s
  
  git checkout -b VOODOO    # 42.363 s
  git diff --quiet          # 41.180 s
  
  git checkout master       # 47.345 s
  git diff --quiet          #  0.018 s
  </code></pre>
  
  <p>I would like to figure out what is going on.  How can I troubleshoot the matter further?</p>
  
  <p>Is there a permanent ("committable") way to "fix" the repo?  (By "fix" I mean: get rid of the long delays for <code>git diff --quiet</code>, <code>git checkout ...</code>, etc.)</p>
  
  <p>(Incidentally, <code>git gc</code> won't fix the repo, even transiently; I tried it.)</p>
  
  <p>I figure that what ends up "fixing" the repo is that <code>git</code> gets around to building <em>and caching</em> some <em>auxiliary data structure</em> that allows it to perform some operations efficiently.  If this hypothesis is correct, then my question can be rephrased as: what is the most direct way to cause <code>git</code> to build such auxiliary data structure?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> One additional bit of information that may shed light on the above is that this repo contains one exceptionally large (1GB) file.  (This explains the slowness of the <code>git clone</code> step.  I don't know if this has anything to do with the slowness of <code>git diff --quiet</code>, etc., and if so, how.)</p>
  
  <hr>
  
  <p><sup><sup>1</sup> Needless to say, I've named the branch <code>VOODOO</code> to reflect my ignorance of what's going on.</sup></p>