title: Can Git really track the movement of a single function from 1 file to another? If so, how?
body: <p>Several times, I have come across the statement that, if you move a single function from one file to another file, Git can track it. For example, <a href="https://stackoverflow.com/questions/1598759/git-and-mercurial-compare-and-contrast/1598812#1598812/">this entry</a> says, "Linus says that if you move a function from one file to another, Git will tell you the history of that single function across the move."</p>
  
  <p>But I have a little bit of awareness of some of Git's under-the-hood design, and I don't see how this is possible. So I'm wondering ... is this is a correct statement? And if so, how is this possible?</p>
  
  <p>My understanding is that Git stores each file's contents as a Blob, and each Blob has a globally unique identity which arises from the SHA hash of its contents and size. Git then represents folders as Trees. Any filename information belongs to the Tree, not to the Blob, so a file rename for example shows up as a change to a Tree, not to a Blob.</p>
  
  <p>So if I have a file called "foo" with 20 functions in it, and a file called "bar" with 5 functions in it, and I move one of the functions from foo into bar (resulting in 19 and 6, respectively), how can Git detect that I moved that function from one file to another?</p>
  
  <p>From my understanding, this would cause 2 new blobs to exist (one for the modified foo and one for the modified bar). I realize a diff could be calculated to show that the function was moved from one file to the other. But I don't see how history about the function could possibly become associated with bar instead of foo (not automatically, anyway).</p>
  
  <p>If Git were to actually look <em>inside</em> of single files, and compute a <em>blob per function</em> (which would be crazy / infeasible, because you'd have to know how to parse any possible language), then I could see how this might be possible.</p>
  
  <p>So ... is the statement correct or not? And if it is correct, then what is lacking in my understanding?</p>