title: git commit leaves changes in the index
body: <h1>The Problem</h1>
  
  <p>I'm attempting to commit some changes, but they're being left behind, for
  reasons I do not understand:</p>
  
  <p>I take a look a the current repo state:</p>
  
  <pre><code>% git status
  On branch new-master
  Changes to be committed:
    (use "git reset HEAD &lt;file&gt;..." to unstage)
  
      new file:   __init__.py
      new file:   api/__init__.py
      new file:   api/api.py
      new file:   api/common.py
      new file:   api/error.py
  
  Changes not staged for commit:
    (use "git add &lt;file&gt;..." to update what will be committed)
    (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)
  
      modified:   ../status/server.py
      modified:   __init__.py
  
  Untracked files:
    (use "git add &lt;file&gt;..." to include in what will be committed)
  
      ../env/
      ../foo.db
  </code></pre>
  
  <p>Messy, but what is in the index is what I want to commit. (<em>Note:</em> there are
  changes that aren't staged: I am <em>not</em> interested in committing those. The
  changes under "Changes to be committed" are the changes I desire to be
  committed.) I commit it:</p>
  
  <pre><code>% git commit -m "Why won't you commit?"
  [new-master a4dbe36] Why won't you commit?
  </code></pre>
  
  <p>And immediately re-run status, to witness nothing has changed:</p>
  
  <pre><code>% git status
  On branch new-master
  Changes to be committed:
    (use "git reset HEAD &lt;file&gt;..." to unstage)
  
      new file:   __init__.py
      new file:   api/__init__.py
      new file:   api/api.py
      new file:   api/common.py
      new file:   api/error.py
  
  Changes not staged for commit:
    (use "git add &lt;file&gt;..." to update what will be committed)
    (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)
  
      modified:   ../status/server.py
      modified:   __init__.py
  
  Untracked files:
    (use "git add &lt;file&gt;..." to include in what will be committed)
  
      ../env/
      ../foo.db
  </code></pre>
  
  <p>If I look at the last commit, we can see that nothing made it in:</p>
  
  <pre><code>% git log -n1 -p
  commit a4dbe36e77a9f3b04c2ef33de75e28b6aa7cac0c
  Author: Me &lt;john.smith@example.com&gt;
  Date:   Fri May 2 11:52:06 2014 -0700
  
      Why won't you commit?
  </code></pre>
  
  <p>What is going on here? <strong>Why aren't these changes committed?</strong></p>
  
  <h1>A minimal testcase!</h1>
  
  <pre><code>mkdir bar &amp;&amp; cd bar
  git init
  echo "data." &gt; some_existing_file
  git add some_existing_file
  git commit -m "Initial commit."
  </code></pre>
  
  <p>That's just set up. Now for the real fun. I get funky behavior with
  <code>--intent-to-add</code> (I may just not understand what it does), but this reproduces
  my full problem:</p>
  
  <pre><code>mkdir subdir &amp;&amp; mkdir subdir/another
  cd subdir
  echo "foodata" &gt; a_file
  echo "more data" &gt; another/other_data
  git add --intent-to-add a_file
  git add another/other_data
  </code></pre>
  
  <p>And then attempt to commit:</p>
  
  <pre><code>git commit -m "Why isn't this committing anything?"
  </code></pre>
  
  <h1>Potentially use outputs</h1>
  
  <p>I don't have any custom hooks (that I'm aware of):</p>
  
  <pre><code>% ls "`git rev-parse --git-dir`"/hooks
  applypatch-msg.sample     pre-applypatch.sample     pre-rebase.sample
  commit-msg.sample         pre-commit.sample         prepare-commit-msg.sample
  post-update.sample        pre-push.sample           update.sample
  </code></pre>
  
  <p>If it matters, the directory the added files are in is new as well, and does
  not exist in the preceeding commit. (I was in the directory itself when I ran
  <code>git status</code>, see the <code>..</code> in the not-staged-for-commit section.)</p>
  
  <p><code>git diff HEAD a4dbe36e77a</code>, as requested, does not output anything.</p>
  
  <p><code>git show</code>:</p>
  
  <pre><code>% git show a4dbe36e77a
  commit a4dbe36e77a9f3b04c2ef33de75e28b6aa7cac0c
  Author: Me &lt;john.smith@example.com&gt;
  Date:   Fri May 2 11:52:06 2014 -0700
  
      Why won't you commit?
  </code></pre>
  
  <p>Also, the same, in raw:</p>
  
  <pre><code>% git show --format=raw a4dbe36e77a
  commit a4dbe36e77a9f3b04c2ef33de75e28b6aa7cac0c
  tree ca9326ccba91dda7540198c082db6e6ab3fb097a
  parent 1842d56d5a47ff33bd420a5014f208c85acc5a1f
  author Me &lt;john.smith@example.com&gt; 1399056726 -0700
  committer Me &lt;john.smith@example.com&gt; 1399056726 -0700
  
      Why won't you commit?
  </code></pre>
  
  <p>An <code>ls-tree</code> of that tree:</p>
  
  <pre><code>% git ls-tree --full-tree ca9326ccba91dda7540198c082db6e6ab3fb097a
  100644 blob fab05d167a3f8ef9ddf00d7af09e00eea03f1d28    requirements.txt
  040000 tree 0d9742d9c1728495d600bde05a7f276f3c65d96d    status
  </code></pre>
  
  <p>For brevity: <code>git diff --staged</code> shows a diff of changes: this is the diff that I desire to be committed, but that <code>git commit</code> isn't committing. (<code>git diff --cached</code> also shows this diff.) <code>git commit -v</code> also shows this diff, but typing a message does not result in a commit.</p>
  
  <p>The only really weird thing about this branch is that it was an orphaned branch — <code>master</code> contains a WIP, but messy version of this code. I was hoping to clean it up, but retain master because I'm human, and worry I'll delete something. However, this isn't the first commit. (The first commit has actual changes, too.) It's only now something's gone wrong.</p>
  
  <h1>Potential clue / something isn't right here:</h1>
  
  <p><strong>EDIT</strong> @torek had me run this:</p>
  
  <pre><code>% git write-tree
  ca9326ccba91dda7540198c082db6e6ab3fb097a
  </code></pre>
  
  <p>This should turn the index's contents into a tree (which could then be attached to a commit object, and thus a commit is born). However, that hash is the same as HEAD. Given that there are changes in my index, one would expect that the tree ID would have to be different. Specifically, these commands show something is odd:</p>
  
  <pre><code>% git write-tree
  ca9326ccba91dda7540198c082db6e6ab3fb097a
  % git diff --staged --stat
   wsgi_util/__init__.py     |  0
   wsgi_util/api/__init__.py |  0
   wsgi_util/api/api.py      | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   wsgi_util/api/common.py   | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   wsgi_util/api/error.py    | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   5 files changed, 235 insertions(+)
  % git write-tree
  ca9326ccba91dda7540198c082db6e6ab3fb097a
  % git show --format=raw HEAD
  commit fe28d60c21e998104e5967faf7af3bf203cd4b26
  tree ca9326ccba91dda7540198c082db6e6ab3fb097a
  parent f86425decfcb3410d5bc90da6ce6146e04775953
  author Me &lt;john.smith@example.com&gt; 1399059521 -0700
  committer Me &lt;john.smith@example.com&gt; 1399059521 -0700
  
      What is going on here?
  </code></pre>
  
  <p><code>git ls-files -s</code>, which seems relevant:</p>
  
  <pre><code>100644 fab05d167a3f8ef9ddf00d7af09e00eea03f1d28 0   requirements.txt
  100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0   status/__init__.py
  100644 923b97d0d9e6c68e77751bb4e7fb14c41fa9d71a 0   status/api/__init__.py
  100644 75f064fc9c170b56545c6b92958b38c10260beec 0   status/api/message.py
  100644 07cf4dc004231945847e9f93e3de214dd02c3661 0   status/api/message_db.py
  100644 78cda37dcc7a4b4f34089b2d843a9abfcd4118cf 0   status/server.py
  100644 bee7c1eb7b92ccf6b78c7dfc5f36e71b77ec5792 0   status/util.py
  100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0   wsgi_util/__init__.py
  100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0   wsgi_util/api/__init__.py
  100644 e92f248874be5beec7b18228d4bf0d062b508916 0   wsgi_util/api/api.py
  100644 68a5a62034d52684222c7075f59f2927c1d8695e 0   wsgi_util/api/common.py
  100644 28d9add6dae84ddab293e3a44cac4824f8d2d482 0   wsgi_util/api/error.py
  </code></pre>
  
  <h1>Another clue?</h1>
  
  <p>Because this was getting significantly in the way, I did a <code>git reset --mixed HEAD</code>. I then proceeded to recreate the index. One of the files, <code>wsgi_util/__init__.py</code> isn't empty, but I wish to commit it (for now) as an empty file: there is no useful code in there. To do this, I have thus far run <code>git add --intent-to-add wsgi_util/__init__.py</code>. I cannot commit this index.</p>
  
  <p>However, I discovered that if I instead replace it with an empty file, and then do a normal <code>git add</code>, the resulting index will commit.</p>