How to "rename" a file in Git after already having moved it with bash/mv
<p>I often rename files with the <code>mv</code> system command, forgetting to use <code>git mv</code> in order to keep the file history:</p>

<pre><code>~/gitproj $ mv myfile.foo newname.foo
</code></pre>

<p>When I realize it before a commit, the only way I know to fix it is to do the following:</p>

<pre><code>~/gitproj $ mv newname.foo myfile.foo        # Coming back to the old name
~/gitproj $ git mv myfile.foo newname.foo    # Moving forth again, but with git
</code></pre>

<p>Is there a better way to do it, like only giving to <code>git</code> the info that the file was moved?</p>

<p>It would be something like that:</p>

<pre><code>~/gitproj $ git mv --cached myfile.foo newname.foo   # a pseudo git command
</code></pre>

<h3>Edit:</h3>

<p>As AndreasGrapentin wrote:</p>

<pre><code>git add .
</code></pre>

<p>let git (auto)detect all the files which were renamed, even if they were modified. But this command adds the whole directory to the index...</p>

<p>Is there a way, even in a lower level, to change this info only for one file?</p>