title: Batch Script: Export last git commit message to a variable
body: <p>I'm trying to assign the last commit message inside a git repository to a variable in a windows batch script and then export the variable. From a lot of questions from StackOverflow, it seems that the command should be:</p>
  
  <pre><code>for /f "Tokens=2" %a in ('git log -1 --pretty=%B') do @set commit_message=%a
  
  export %commit_message%
  </code></pre>
  
  <p>But it's giving the following error.</p>
  
  <pre><code>fatal: ambiguous argument '%B': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git &lt;command&gt; [&lt;revision&gt;...] -- [&lt;file&gt;...]'
  </code></pre>
  
  <p>In Linux it is quite straight forward. Only <code>export commit_message=$(git log -1 --pretty=%B)</code>. </p>