Re: git index: how does it work?
From: Björn Steinbrink <hidden>
Date: 2016-06-15 22:47:13
[Please don't top-post, fixed that for you...] On 2009.08.12 20:45:48 +0200, Shaun Cutts wrote:
On Aug 12, 2009, at 7:47 PM, Sverre Rabbelier wrote:quoted
Heya, On Wed, Aug 12, 2009 at 04:52, Shaun Cutts[off-list ref] wrote:quoted
Are renames being tracked by the index, and is there a more basic interface than "status" to query about them?Nope, git never explicitly tracks renames. Try this: $ mv foo bar $ git rm --cached foo $ git add bar $ git status It'll tell you that you renamed foo to bar, even if you never executed 'git mv'. This is because git does rename _detection_, that is, it'll notice that you have another file with (almost) the same contents, so it assumes you did a rename.Aha --- that explains it, then. Is there a lower-level interface to rename detection than via "status"? And... um... hmmm.... how does it work? The hash codes don't help for "almost" the same. Is there an approximate string matching algorithm built in somewhere?
Roughly, it works like this: The files are split into small chunks, those are hashed, and if there are chunks with the same hash in both files, those chunks are treated as being common to both files. The more the files have in common, the higher the similarity score. See estimate_similarity() for details. As the splitting also happens at newlines this has some interesting effects, for example, you can completely reorder the lines in a file after renaming it, and git will still detect it as a rename. Björn