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

Re: Strange diff-index output

From
Jeff King <peff@peff.net>
Date
Nov 4, 2015, 06:38 UTC
Message-ID
<20151104063803.GA16605@sigill.intra.peff.net>
In-Reply-To
<CABxGUTihNmHqp-RovCVreTRqoK_sj+KCjRQE_YOVZ8OQzOHHoA@mail.gmail.com>
On Tue, Nov 03, 2015 at 02:00:33PM +1300, Ch'Gans wrote:
> I first tried "git update-index" but it didn't work. However "git
> update-index --refresh" seems to fix our problem.
> I didn't get why "--refresh" is needed thought, I'm really not
> familiar with the caching aspect of git.

It is because update-index is a general command for manipulating the index. For example, you can add, delete, or change entries without regard to what is in the working tree.

One of the manipulations is "refresh the index based on what is in the working tree", and that is spelled "--refresh". Most porcelain-level git commands (like "git diff") will do this for you automatically and transparently. But when using the scriptable plumbing (like diff-index), git gives you more control. This lets you do things more efficiently (e.g,. you might refresh once and then issue several low-level commands), at the cost of convenience.

You could also have used "git diff-index --cached HEAD", which instructs diff-index not to look at the working tree at all (so you would compare whatever is in the index, whether it is up to date with what is in the working tree or not). Depending on what you are trying to achieve, that might be fine (it's also more efficient in general, as it does not require an lstat() of every file in the working tree).

-Peff
Previous: Ch'Gans
Message 4 of 4 in “Strange diff-index output”
  1. Ch'GansNov 2, 2015
  2. David TurnerNov 3, 2015
  3. Ch'GansNov 3, 2015
  4. Jeff KingNov 4, 2015

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.