git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git index: how does it work?

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 12, 2009, 20:31 UTC
Message-ID
<7vab24ydsz.fsf@alter.siamese.dyndns.org>
In-Reply-To
<436D5ED1-2F0E-4227-AC4A-3A5FD16B2DCF@cuttshome.net>
Shaun Cutts <shaun@cuttshome.net> writes:
> Are renames being tracked by the index, and is there a more basic
> interface than "status" to query about them?

No. Index, nor git in general, never records renames. git records contents, not content changes. The index records a state, so does the tree object pointed at by the HEAD commit.

When you ask for "status", git will notice that you have lost a file, and added a new one, between these two states, by comparing them. The contents of these lost files and added files are then compared, and ones with similar contents are paired up.

That way, you do not have to use "git mv A B" to "rename" A to B. You can just as well "mv A B; git rm A; git add B", and get the same outcome, exactly because git does not record renames.

Instead, we track them by deducing that you renamed from the result.

The tree-vs-index comparison "git status" does to figure all this out is "git diff-index -M --cached HEAD".

As it should be obvious from the above description,
	git diff-index -M --cached HEAD -- A

is *NOT* the way for you to ask about "possible renames of A". You need to run the diff for the whole tree without path limitation so that you can pair deletions and creations up in order to deduce renames.

Previous: Björn SteinbrinkNext: Sverre Rabbelier
Message 7 of 9 in “git index: how does it work?”
  1. Shaun CuttsAug 5, 2009
  2. Junio C HamanoAug 5, 2009
  3. Shaun CuttsAug 12, 2009
  4. Sverre RabbelierAug 12, 2009
  5. Shaun CuttsAug 12, 2009
  6. Björn SteinbrinkAug 12, 2009
  7. Junio C HamanoAug 12, 2009
  8. Sverre RabbelierAug 5, 2009
  9. Shaun CuttsAug 5, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.