title: Programmatically swap last two commits
body: <p>I know how to swap the last two commits using <code>git rebase</code> interactively (<code>git rebase -i HEAD~2</code>, <code>ddjp:x</code> in Vim), but I'd like to do it programmatically with a wrapper script since it's something I end up doing relatively often.</p>
  
  <p>To be more concrete, I want to rewrite history from</p>
  
  <pre><code>A---B---C---D HEAD
  </code></pre>
  
  <p>to</p>
  
  <pre><code>A---B---D---C HEAD
  </code></pre>
  
  <p>in an entirely scripted manner. Ideally, if the swap fails, it should either allow me to fix it interactively or just give up and tell me to do it manually.</p>