git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-diff new files (without using index)
@ 2007-08-05  3:42 Miles Bader
  2007-08-05  3:52 ` Shawn O. Pearce
  0 siblings, 1 reply; 6+ messages in thread
From: Miles Bader @ 2007-08-05  3:42 UTC (permalink / raw)
  To: git

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).

Is there anyway to do this currently?  If not, maybe something like a
"git-diff -N" (mirroring diff's -N/--new-file option) option could be
added to do this?

Thanks,

-Miles
-- 
=====
(^o^;
(()))
*This is the cute octopus virus, please copy it into your sig so it can spread.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git-diff new files (without using index)
  2007-08-05  3:42 git-diff new files (without using index) Miles Bader
@ 2007-08-05  3:52 ` Shawn O. Pearce
  2007-08-05  4:00   ` Miles Bader
  0 siblings, 1 reply; 6+ messages in thread
From: Shawn O. Pearce @ 2007-08-05  3:52 UTC (permalink / raw)
  To: Miles Bader; +Cc: git

Miles Bader <miles@gnu.org> wrote:
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git-diff new files (without using index)
  2007-08-05  3:52 ` Shawn O. Pearce
@ 2007-08-05  4:00   ` Miles Bader
  2007-08-05  4:08     ` Shawn O. Pearce
  0 siblings, 1 reply; 6+ messages in thread
From: Miles Bader @ 2007-08-05  4:00 UTC (permalink / raw)
  To: git

"Shawn O. Pearce" <spearce@spearce.org> writes:
>> 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
>
> Use a temporary index:
...
> Another option is to just add everything, then reset the index:
...
> Granted if you had other files staged they just became unstaged
> and will need to be restaged...  the temporary index trick above
> avoids that.

Thanks for the tip (I guess I can roll my own "git-diff-uncached"
script)!

The above sort of quirkiness does seem kind of a wart though; in my
(admittedly limited, using git) experience this sort of thing really
reduces the utility of the index, and I often end up feeling like it's
just getting in the way as a result.  Does adding something like a
"git-diff -N" option seem a _bad_ idea?

Thanks,

-Miles

-- 
"Suppose He doesn't give a shit?  Suppose there is a God but He
just doesn't give a shit?"  [George Carlin]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git-diff new files (without using index)
  2007-08-05  4:00   ` Miles Bader
@ 2007-08-05  4:08     ` Shawn O. Pearce
  2007-08-05  4:20       ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Shawn O. Pearce @ 2007-08-05  4:08 UTC (permalink / raw)
  To: Miles Bader; +Cc: git

Miles Bader <miles@gnu.org> wrote:
> Thanks for the tip (I guess I can roll my own "git-diff-uncached"
> script)!

Indeed, Git is quite scriptable.  ;-)
 
> The above sort of quirkiness does seem kind of a wart though; in my
> (admittedly limited, using git) experience this sort of thing really
> reduces the utility of the index, and I often end up feeling like it's
> just getting in the way as a result.  Does adding something like a
> "git-diff -N" option seem a _bad_ idea?

I'm not interested in such an option.  Typically if I want a
diff on a new untracked file I actually want that file in my next
commit anyway.  So I'm usually staging it into the index along with
everything else that I have modified.  In which case this quirkiness
isn't really a quirk at all.  Its just not an issue to me.

If you want to try adding it, go right ahead.  The source for git
is stored in git and available from many places.  :-)

-- 
Shawn.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git-diff new files (without using index)
  2007-08-05  4:08     ` Shawn O. Pearce
@ 2007-08-05  4:20       ` Junio C Hamano
  2007-08-05  4:37         ` Miles Bader
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2007-08-05  4:20 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Miles Bader, git

"Shawn O. Pearce" <spearce@spearce.org> writes:

>> The above sort of quirkiness does seem kind of a wart though; in my
>> (admittedly limited, using git) experience this sort of thing really
>> reduces the utility of the index, and I often end up feeling like it's
>> just getting in the way as a result.  Does adding something like a
>> "git-diff -N" option seem a _bad_ idea?
>
> I'm not interested in such an option.  Typically if I want a
> diff on a new untracked file I actually want that file in my next
> commit anyway.

I suspect that it's probably half superstition and half disease
to wish for "diff /dev/null new-file".  Even CVS got this one
right by saying "is a new file, no diff available".  The
contents of that new file is available in "less new-file" near
you anyway and it is quite pointless while you are working
toward next commit.  It just is not interesting, until you tell
git you _care_ about that file.  And the way you tell git about
it is with "git add".

Learn to love the index, run "git-add" and view "git-diff HEAD".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: git-diff new files (without using index)
  2007-08-05  4:20       ` Junio C Hamano
@ 2007-08-05  4:37         ` Miles Bader
  0 siblings, 0 replies; 6+ messages in thread
From: Miles Bader @ 2007-08-05  4:37 UTC (permalink / raw)
  To: git

Junio C Hamano <gitster@pobox.com> writes:
> I suspect that it's probably half superstition and half disease
> to wish for "diff /dev/null new-file".

Er, please, a bit of consideration.  It's not superstition, it's not a disease.

I _want to use the index_:  I want to stage changes, and then make more
changes, and just generally be able to treat these three states (HEAD,
indexed, non-indexed) as points which can be used as inputs to git-diff
-- and I want _applyable patch files_ as the output from git-diff, not
pretty diffs for browsing.

Thanks,

-Miles

-- 
Any man who is a triangle, has thee right, when in Cartesian Space, to
have angles, which when summed, come to know more, nor no less, than
nine score degrees, should he so wish.  [TEMPLE OV THEE LEMUR]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-08-05  4:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-05  3:42 git-diff new files (without using index) Miles Bader
2007-08-05  3:52 ` Shawn O. Pearce
2007-08-05  4:00   ` Miles Bader
2007-08-05  4:08     ` Shawn O. Pearce
2007-08-05  4:20       ` Junio C Hamano
2007-08-05  4:37         ` Miles Bader

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).