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

Re: [PATCH] git-diff: Add --staged as a synonym for --cached.

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 12, 2008, 11:10 UTC
Message-ID
<alpine.DEB.1.00.0811121205100.30769@pacific.mpi-cbg.de>
In-Reply-To
<20081112083353.GB3817@coredump.intra.peff.net>
Hi,
On Wed, 12 Nov 2008, Jeff King wrote:
Show 18 quoted lines
> On Mon, Nov 10, 2008 at 11:04:42PM -0500, Avery Pennarun wrote:
> 
> > Speaking just for myself, I would find this all a lot less confusing 
> > if "staged" were a refspec of some sort, not an option at all.
> > 
> >    git diff HEAD..STAGED
> >    git diff STAGED..WORKTREE
> >    git grep pattern STAGED HEAD sillybranch WORKTREE ^ignorebranch --
> > path/to/files
> 
> I agree that such a thing is reasonably intuitive. I have thought about 
> "magic" refspecs before; my local git has an "EMPTY" refspec which 
> points to the empty tree for diffing. However, that was trivial to 
> implement (since it turns into a sha1), and yours is very hard (since 
> you will have to pass these "pretend" objects around).
> 
> So I think it is a neat idea, but I am not volunteering to work on it.
> :)

Just in case anybody thought about creating tree objects on the fly and use their SHA-1s: that won't fly, as you can have unmerged entries in the index. So STAGED.. is a _fundamentally_ different thing from HEAD^..

Maybe we could play tricks with a special staged_commit (pretending to be a commit with SHA-1 000000... so that git log STAGED.. would do the same as plain git log, the rationale being that STAGED is no commit, so ^STAGED should be a nop).

"git diff" would then have some special handling for the case that there are exactly two revs, exactly one of them negative, and exactly one of them being the staged_commit, passing off to the respective diff backends.

Ciao, Dscho

Previous: Jeff KingNext: Jeff King
Message 20 of 29 in “git-diff: Add --staged as a synonym for --cached.”
  1. git-diff: Add --staged as a synonym for --cached.David Symonds, Oct 29, 2008
  2. Jeff KingOct 29, 2008
  3. David SymondsOct 29, 2008
  4. Johannes SchindelinOct 29, 2008
  5. Jeff KingOct 29, 2008
  6. Junio C HamanoNov 2, 2008
  7. Jeff KingNov 3, 2008
  8. Björn SteinbrinkNov 2, 2008
  9. Junio C HamanoNov 2, 2008
  10. Björn SteinbrinkNov 2, 2008
  11. Jeff KingNov 3, 2008
  12. David SymondsNov 10, 2008
  13. Jeff KingNov 11, 2008
  14. Junio C HamanoNov 11, 2008
  15. Jeff KingNov 11, 2008
  16. Junio C HamanoNov 12, 2008
  17. Avery PennarunNov 11, 2008
  18. Miles BaderNov 11, 2008
  19. Jeff KingNov 12, 2008
  20. Johannes SchindelinNov 12, 2008
  21. Jeff KingNov 12, 2008
  22. Avery PennarunNov 12, 2008
  23. Jeff KingNov 12, 2008
  24. Junio C HamanoNov 12, 2008
  25. Jeff KingNov 12, 2008
  26. Junio C HamanoNov 12, 2008
  27. Avery PennarunNov 12, 2008
  28. Junio C HamanoNov 12, 2008
  29. Avery PennarunNov 12, 2008

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.