Skip to contentSkip to conversation

Implement git-staged, an alias for 'git diff --cached'.

PATCH In review David Symonds 10 participants 25 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Implement git-staged, an alias for 'git diff --cached'.

---
This isn't a particularly serious patch, but is very relevant to our current discussion at GitTogether '08.

 .gitignore    |    1 +
 Makefile      |    1 +
 git-staged.sh |    8 ++++++++
 3 files changed, 10 insertions(+), 0 deletions(-)
 create mode 100755 git-staged.sh
.gitignore +1 -0
index bbaf9de..9353d19 100644
@@ -118,6 +118,7 @@ git-show
 git-show-branch
 git-show-index
 git-show-ref
+git-staged
 git-stash
 git-status
 git-stripspace
Makefile +1 -0
index d6f3695..1b23e53 100644
@@ -262,6 +262,7 @@ SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
 SCRIPT_SH += git-sh-setup.sh
+SCRIPT_SH += git-staged.sh
 SCRIPT_SH += git-stash.sh
 SCRIPT_SH += git-submodule.sh
 SCRIPT_SH += git-web--browse.sh
git-staged.sh new file +8 -0
new file mode 100755
index 0000000..bfd36e7
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+USAGE=''
+SUBDIRECTORY_OK='Yes'
+OPTIONS_SPEC=
+. git-sh-setup
+
+git diff --cached
Signature · 1 line
1.6.0
#1 lore raw

PATCH 1/1 Implement git-staged, an alias for 'git diff --cached'.

---
 .gitignore    |    1 +
 Makefile      |    1 +
 git-staged.sh |    2 ++
 3 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100755 git-staged.sh
.gitignore +1 -0
index bbaf9de..9353d19 100644
@@ -118,6 +118,7 @@ git-show
 git-show-branch
 git-show-index
 git-show-ref
+git-staged
 git-stash
 git-status
 git-stripspace
Makefile +1 -0
index d6f3695..1b23e53 100644
@@ -262,6 +262,7 @@ SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
 SCRIPT_SH += git-sh-setup.sh
+SCRIPT_SH += git-staged.sh
 SCRIPT_SH += git-stash.sh
 SCRIPT_SH += git-submodule.sh
 SCRIPT_SH += git-web--browse.sh
git-staged.sh new file +2 -0
new file mode 100755
index 0000000..85582ec
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec git diff --cached $*
Signature · 1 line
1.6.0
#2 lore raw

git-staged.sh line 2

Quoted 5 lines · David Symonds
git-staged.sh new file +2 -0
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec git diff --cached $*

This is broken for arguments with spaces. Use "$@" instead.

But I think this isn't a serious patch anyway, so we are probably wasting too much time on it. ;P

-Peff

#3 lore raw

PATCH 1/1 Implement git-staged, an alias for 'git diff --cached'.

---
 .gitignore    |    1 +
 Makefile      |    1 +
 git-staged.sh |    2 ++
 3 files changed, 4 insertions(+), 0 deletions(-)
 create mode 100755 git-staged.sh
.gitignore +1 -0
index bbaf9de..9353d19 100644
@@ -118,6 +118,7 @@ git-show
 git-show-branch
 git-show-index
 git-show-ref
+git-staged
 git-stash
 git-status
 git-stripspace
Makefile +1 -0
index d6f3695..1b23e53 100644
@@ -262,6 +262,7 @@ SCRIPT_SH += git-rebase.sh
 SCRIPT_SH += git-repack.sh
 SCRIPT_SH += git-request-pull.sh
 SCRIPT_SH += git-sh-setup.sh
+SCRIPT_SH += git-staged.sh
 SCRIPT_SH += git-stash.sh
 SCRIPT_SH += git-submodule.sh
 SCRIPT_SH += git-web--browse.sh
git-staged.sh new file +2 -0
new file mode 100755
index 0000000..66a5e33
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec git diff --cached "$@"
Signature · 1 line
1.6.0
#4 lore raw
Quoted 1 line · David Symonds

+SCRIPT_SH += git-staged.sh

Isn't this exactly what aliases are for?
git config --global alias.staged "diff --cached"
(Rather than adding yet another command...)

Wincent

#5 lore raw

Hi,

Quoted 7 lines · Wincent Colaiuta
Quoted 1 line · David Symonds

+SCRIPT_SH += git-staged.sh

Isn't this exactly what aliases are for?
git config --global alias.staged "diff --cached"
(Rather than adding yet another command...)

The difference being, of course, that we do not ship default aliases (and neither do we plan to...).

So saying "this is what aliases are for" you ask for _newbies_ to add it for themselves. We are talking the same newbies who should be helped by that command, and typically do not know that there are Git aliases yet.

Even worse, just sum the times it takes everybody to make that alias, and then compare with the time it would take to include something like David posted in git.git. It should be obvious that the time balance is absolutely horrible.

Ciao,
Dscho

#6 lore raw
Quoted 23 lines · Johannes Schindelin

Hi,

Quoted 7 lines · Wincent Colaiuta
Quoted 1 line · David Symonds

+SCRIPT_SH += git-staged.sh

Isn't this exactly what aliases are for?
git config --global alias.staged "diff --cached"
(Rather than adding yet another command...)

The difference being, of course, that we do not ship default aliases (and
neither do we plan to...).

So saying "this is what aliases are for" you ask for _newbies_ to add it
for themselves. We are talking the same newbies who should be helped by
that command, and typically do not know that there are Git aliases yet.

Quoted 6 lines

Even worse, just sum the times it takes everybody to make that alias, and
then compare with the time it would take to include something like David
posted in git.git. It should be obvious that the time balance is absolutely horrible.

Git already has too many commands. Adding more is not going to clear up newbie confusion, and will only waste time because people will complain about it and ask why there is this kind of duplication.

W

#7 lore raw

Hi,

Quoted 3 lines · Wincent Colaiuta

Git already has too many commands. Adding more is not going to clear up newbie confusion, and will only waste time because people will complain about it and ask why there is this kind of duplication.

I completely disagree. If the existing set of commands causes confusion, we need to deprecate those parts and add new commands. Even if we have a ton of commands already.

It does not need to hurt, either. Just think of init-db. Ever heard of it? We still have it, yet it is not relevant.

Ciao,
Dscho

#8 lore raw
Quoted 6 lines · Johannes Schindelin

I completely disagree. If the existing set of commands causes confusion, we need to deprecate those parts and add new commands. Even if we have a ton of commands already.

It does not need to hurt, either. Just think of init-db. Ever heard of it? We still have it, yet it is not relevant.

In this specific case adding a new command as an alias for a command+option seems wrong! I much prefer adding the alias --staged for --cached - as proposed now - if it can make things easier for new comers.

Pascal.

Signature · 8 lines
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
#9 lore raw
In reply to Johannes Schindelin
Quoted 10 lines · Johannes Schindelin

Hi,

Quoted 5 lines · Wincent Colaiuta

Git already has too many commands. Adding more is not going to clear up
newbie confusion, and will only waste time because people will complain
about it and ask why there is this kind of duplication.

Quoted 5 lines

I completely disagree. If the existing set of commands causes confusion,
we need to deprecate those parts and add new commands. Even if we have a
ton of commands already.

The confusion isn't at the command level; it's at the switch/option level. The solution isn't to add a new command.

Quoted 3 lines

It does not need to hurt, either. Just think of init-db. Ever heard of
it? We still have it, yet it is not relevant.

The comparison isn't really valid. init-db is effectively invisible, but you're talking about adding a new "in your face" porcelain command.

W

#10 lore raw
Quoted 7 lines · Wincent Colaiuta (2008-10-29 18:42 +0100) wrote:
Quoted 3 lines · Johannes Schindelin

I completely disagree. If the existing set of commands causes confusion, we need to deprecate those parts and add new commands. Even if we have a ton of commands already.

The confusion isn't at the command level; it's at the switch/option level. The solution isn't to add a new command.

I don't remember being confused in particular area but I think it's a _very_ good thing that the following three are behind the same "diff" command:

git diff
git diff --cached (or --staged)
git diff HEAD

It's also good idea to pretty much always teach those three together.

#11 lore raw
Quoted 10 lines · Teemu Likonen
Quoted 7 lines · Wincent Colaiuta (2008-10-29 18:42 +0100) wrote:
Quoted 3 lines · Johannes Schindelin

I completely disagree. If the existing set of commands causes confusion, we need to deprecate those parts and add new commands. Even if we have a ton of commands already.

The confusion isn't at the command level; it's at the switch/option level. The solution isn't to add a new command.

Quoted 7 lines

I don't remember being confused in particular area but I think it's a _very_ good thing that the following three are behind the same "diff" command:

git diff
git diff --cached (or --staged)
git diff HEAD

One irregularity hear is that there is no way to explicitly say what you want to compare against the index (the staging area). Diff compares two things to each other, and a more regular and general way to express what it does would be something like

    git diff STAGE WORKTREE   (like "git diff" today)
    git diff HEAD WORKTREE    (like "git diff HEAD" today)
    git diff WORKTREE HEAD    (like "git diff -R HEAD" today)
    git diff HEAD STAGE       (like "git diff --cached" today)
    git diff commit STAGE     (like "git diff --cached commit" today)

To me, it isn't obvious that --cached changes the thing you *compare* rather than the thing you compare *against*. I think it would be useful to have a way of explicitly stating what you compare, something like what I wrote above, and then having useful shortcuts for common cases (like that no arguments compares the work tree against the stage).

Signature · 1 line
David Kågedal
#12 lore raw
In reply to Wincent Colaiuta

Hi,

Quoted 8 lines · Wincent Colaiuta
Quoted 6 lines · Johannes Schindelin
Quoted 3 lines · Wincent Colaiuta

Git already has too many commands. Adding more is not going to clear up newbie confusion, and will only waste time because people will complain about it and ask why there is this kind of duplication.

Quoted 6 lines
Quoted 3 lines

I completely disagree. If the existing set of commands causes confusion, we need to deprecate those parts and add new commands. Even if we have a ton of commands already.

The confusion isn't at the command level; it's at the switch/option level. The solution isn't to add a new command.

Seems that at leat one guy who does Git training disagrees with you, _in addition_ to me.

Ciao,
Dscho

#13 lore raw
Quoted 17 lines · Johannes Schindelin

Hi,

Quoted 13 lines · Wincent Colaiuta
Quoted 10 lines · Johannes Schindelin
Quoted 4 lines · Wincent Colaiuta

Git already has too many commands. Adding more is not going to clear
up newbie confusion, and will only waste time because people will complain about it and ask why there is this kind of duplication.

I completely disagree. If the existing set of commands causes confusion, we need to deprecate those parts and add new commands. Even if we have a ton of commands already.

Quoted 6 lines
Quoted 2 lines

The confusion isn't at the command level; it's at the switch/option level. The solution isn't to add a new command.

Seems that at leat one guy who does Git training disagrees with you, _in
addition_ to me.

That's what I call a "zero value" addition to the thread, seeing as anyone reading the thread _already_ knows the opinions of the participants who've posted.

Adding a separate command to an already overwhelming command set in order to address confusion about options to "git diff" is a case of "duct-tape UI design".

Wincent

#14 lore raw
In reply to Johannes Schindelin

Hi,

Quoted 3 lines · Johannes Schindelin

So saying "this is what aliases are for" you ask for _newbies_ to add it for themselves. We are talking the same newbies who should be helped by that command, and typically do not know that there are Git aliases yet.

I'm not sure if yet more commands really help newbies.

I *see* the problem that talking about the index, the cache and the staging area can be difficult to newbies. But then I'd rather vote for "git diff --staged" (instead of --cached) or "git show --staged" (both make sense in some way).
Perhaps it is even sufficient to add a help text to "git status", like this:

# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
+# (use "git diff --cached" to see a diff of staged files)

For me, a "git staged" feels wrong without a "git stage" (alias for "git add") and "git unstage <file>" (alias for "git reset <file>"). And I think the list of examples can easily be continued.

Regards,
Stephan

Signature · 1 line
Stephan Beyer <[email protected]>, PGP 0x6EDDD207FCC5040F
#16 lore raw
In reply to David Symonds

Hi,

.gitignore git-show · line 121

Quoted 9 lines · David Symonds
.gitignore +1 -0
index bbaf9de..9353d19 100644
@@ -118,6 +118,7 @@ git-show
 git-show-branch
 git-show-index
 git-show-ref
+git-staged

Would it not be better to teach "git show --staged" to do that, and to add a command pair "git stage <file>" and "git unstage <file>" to do the obvious?

Ciao,
Dscho

#17 lore raw
Quoted 5 lines · Johannes Schindelin
Quoted 1 line

+git-staged

Would it not be better to teach "git show --staged" to do that, and to add a command pair "git stage <file>" and "git unstage <file>" to do the obvious?

Yes, I think half of the discussion went on IRC. But I don't think "git staged" is a good idea. I think a "--staged" alias for "--cached" in "git diff" makes a lot more sense.

-Peff

#18 lore raw
In reply to Jeff King

Hi,

Quoted 10 lines

git-staged.sh line 2

Quoted 5 lines
git-staged.sh new file +2 -0
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec git diff --cached $*

This is broken for arguments with spaces. Use "$@" instead.

But I think this isn't a serious patch anyway, so we are probably wasting too much time on it. ;P

I'm still not understanding, what it's for.
Usability? Because doing

	git config --global alias.staged 'diff --cached'

is lame?

Regards,
Stephan

PS: Btw, if ever meant serious, it's missing an insertion into
command-list.txt and serious documentation.
But I think you know that. :-)

Signature · 1 line
Stephan Beyer <[email protected]>, PGP 0x6EDDD207FCC5040F
#19 lore raw
Quoted 4 lines · Stephan Beyer

I'm still not understanding, what it's for.
Usability? Because doing

	git config --global alias.staged 'diff --cached'

is lame?

You are missing some of the context, which is that we just had a big in-person debate about how the staged nomenclature is confusing. We call things "cached", "staged", and "index", depending on the command.

So this is an attempt to rectify that.

-Peff

#20 lore raw
Quoted 8 lines · Jeff King
Quoted 4 lines · Stephan Beyer

I'm still not understanding, what it's for.
Usability? Because doing

	git config --global alias.staged 'diff --cached'

is lame?

You are missing some of the context,

Yeah, it would have been nice if there was audio.
Anyone take minutes, possibly?

btw the term "staged" makes perfect sense to me, whereas "cached" was not intuitively obvious to me.

-brandon

#21 lore raw
Quoted 4 lines · Brandon Casey
Quoted 1 line

You are missing some of the context,

Yeah, it would have been nice if there was audio.
Anyone take minutes, possibly?

There's no audio. Some of the slides will be available. I took notes on at least one of the discussions, which I will try to summarize and post. And I think some of the discussion will end up as patches, which will hopefully provide full justification in their commit messages. ;)

-Peff

#22 lore raw
In reply to David Symonds

git-staged.sh line 8

Quoted 11 lines · David Symonds
git-staged.sh new file +8 -0
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+USAGE=''
+SUBDIRECTORY_OK='Yes'
+OPTIONS_SPEC=
+. git-sh-setup
+
+git diff --cached

Do you even need to do sh-setup? How about

  #!/bin/sh
  exec git diff --cached "$@"

-Peff

#23 lore raw
In reply to David Symonds

What about :

   $ git config --global alias.staged "diff --cached"

I'm using this since some time.

Signature · 8 lines
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
#24 lore raw
In reply to David Symonds
Quoted 4 lines · David Symonds

---
This isn't a particularly serious patch, but is very relevant to our current discussion at GitTogether '08.

I've thought about some commands like:
git stage $file (git add $file)
git unstage $file (git reset $file)

Perhaps
git stage add
git stage rm

And then your proposal would fit with:
git stage diff

Or something like that.

Signature · 1 line
Felipe Contreras