title: How do I get the output from a call to GIT into a variable in a batch script?
body: <p>I have a git command to get the latest SHA of the current repo as follows:</p>
  
  <pre><code>git log --pretty=format:"%H" -n 1
  </code></pre>
  
  <p>I have a windows batch script I'd like to use this in as follows:</p>
  
  <pre><code>SET CURRENT_SHA=???
  </code></pre>
  
  <p>But I'm at a loss as to how to get the output from that call to git into the variable so that I can make use of it.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I've tried the following (which seems to be the general advice I've read here and elsewhere):</p>
  
  <pre><code>SETLOCAL ENABLEDELAYEDEXPANSION
  FOR /F "tokens=* USEBACKQ" %%i IN (`git log --pretty=format:"%H" -n 1`) DO (SET CURRENT_SHA=%%i)
  ECHO Current Sha: %CURRENT_SHA%
  </code></pre>
  
  <p>..but I get:</p>
  
  <pre><code>fatal: failed to stat 'format:i) ECHO Current Sha: 48bce83e800b96607afb2a387c4fcd7b0b0f037e
  </code></pre>
  
  <p>So presumably there's a problem with the quotes?</p>