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

Re: git-diff new files (without using index)

From
Shawn O. Pearce <spearce@spearce.org>
Date
Aug 5, 2007, 03:52 UTC
Message-ID
<20070805035245.GE9527@spearce.org>
In-Reply-To
<87wswalkad.fsf@catnip.gol.com>
Miles Bader <miles@gnu.org> wrote:
Show 8 quoted lines
> One thing I often want to do is generate a complete diff of all changes,
> including new/removed files.
> 
> If I add things to the index, I can use "git-diff --cached" to do it;
> however I'd actually like to be able to do this _without_ updating the
> index; in other words, any un-added new file as a change.  As it is, the
> "non-indexed" state seems kind of a second-class citizen, as you can
> never have new files there (or rather, git will never really see them).
 
Use a temporary index:
  (export GIT_INDEX_FILE=.git/tempindex;
   cp .git/index $GIT_INDEX_FILE;
   git add new-file;
   git add other-new-file;
   git diff --cached)

We pull this trick sometimes in internal tools, when we want to produce some result but aren't sure we want to keep the resulting index, or really know we don't want to keep the resulting index.

Another option is to just add everything, then reset the index:
  git add new-file
  git add other-new-file
  git diff --cached
  git reset

Granted if you had other files staged they just became unstaged and will need to be restaged... the temporary index trick above avoids that.

-- 
Shawn.
Previous: Miles BaderNext: Miles Bader
Message 2 of 6 in “git-diff new files (without using index)”
  1. Miles BaderAug 5, 2007
  2. Shawn O. PearceAug 5, 2007
  3. Miles BaderAug 5, 2007
  4. Shawn O. PearceAug 5, 2007
  5. Junio C HamanoAug 5, 2007
  6. Miles BaderAug 5, 2007

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.