title: Handling file renames in Git
body: <p>I'd read that when <a href="https://bauermann.wordpress.com/2008/01/03/take-care-when-renaming-files-in-git/" rel="noreferrer">renaming files in Git</a>, you should commit any changes, perform your rename and then stage your renamed file. Git will recognise the file from the contents, rather than seeing it as a new untracked file, and keep the change history.</p>
  <p>However, doing just this tonight I ended up reverting to <code>git mv</code>.</p>
  <pre><code>&gt; $ git status
  # On branch master
  # Changes to be committed:
  #   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
  #
  #    modified:   index.html
  #
  </code></pre>
  <p>I renamed my stylesheet in <a href="https://en.wikipedia.org/wiki/Finder_(software)" rel="noreferrer">Finder</a> from <code>iphone.css</code> to <code>mobile.css</code>:</p>
  <pre><code>&gt; $ git status
  # On branch master
  # Changes to be committed:
  #   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
  #
  #    modified:   index.html
  #
  # Changed but not updated:
  #   (use &quot;git add/rm &lt;file&gt;...&quot; to update what will be committed)
  #   (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
  #
  #    deleted:    css/iphone.css
  #
  # Untracked files:
  #   (use &quot;git add &lt;file&gt;...&quot; to include in what will be committed)
  #
  #    css/mobile.css
  </code></pre>
  <p>So Git now thinks I've deleted one CSS file, and added a new one. It is not what I want. Let’s undo the rename and let Git do the work.</p>
  <pre><code>&gt; $ git reset HEAD .
  Unstaged changes after reset:
  M    css/iphone.css
  M    index.html
  </code></pre>
  <p>I am back to where I began:</p>
  <pre><code>&gt; $ git status
  # On branch master
  # Changes to be committed:
  #   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
  #
  #    modified:   index.html
  #
  </code></pre>
  <p>Let's use <code>git mv</code> instead:</p>
  <pre><code>&gt; $ git mv css/iphone.css css/mobile.css
  &gt; $ git status
  # On branch master
  # Changes to be committed:
  #   (use &quot;git reset HEAD &lt;file&gt;...&quot; to unstage)
  #
  #    renamed:    css/iphone.css -&gt; css/mobile.css
  #
  # Changed but not updated:
  #   (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
  #   (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)
  #
  #    modified:   index.html
  #
  </code></pre>
  <p>It looks like we're good. So why didn't Git recognise the rename the first time around when I used Finder?</p>