threads / discuss / 24174

Newbie question: how can I list added files?

Subject: Newbie question: how can I list added files?

## tl;dr

9 messages between Jun 23, 2010 and Jun 23, 2010.

replies: 8people: 6as markdown or json

Bruce Korb· Jun 23, 2010, 17:31 UTC · lore

git-ls-files doesn't seem to have an option for it, neither does git-add. Seems like it ought to be trivial, but I'm not seeing how to do it. :( Thank you!!

P.S.: yes, I know I can parse the output from git-status. I'd really rather not for various reasons. If it's the only way, then I'll do the only thing.

Bruce Korb· Jun 23, 2010, 17:50 UTC · re: Junio C Hamano · lore

Re: Newbie question: how can I list added files?

On Wed, Jun 23, 2010 at 10:43 AM, Junio C Hamano <gitster@pobox.com> wrote:
> "git diff --name-only --diff-filter=A HEAD"?

Thank you, but "Nope." My added file doesn't show anything and not using the "--diff-filter" thing shows both added and not added files:

$ git diff --name-only --diff-filter=A HEAD $ git-status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: sw/embedded/platform/strad/scripts/mk_relsrc.sh [...] $ git diff --name-only HEAD chip/chopin2/up/hdl/.sopc_builder/install.ptf chip/mozart/up_oam/hdl/.sopc_builder/install.ptf chip/mozart2/up/hdl/.sopc_builder/install.ptf chip/mozart2/up_ft/hdl/.sopc_builder/install.ptf sw/embedded/nios2/system/system.stf sw/embedded/platform/strad/scripts/mk_relsrc.sh sw/projects/nios2/modules/system/lib/system.stf $

Junio C Hamano· Jun 23, 2010, 18:28 UTC · re: Bruce Korb · lore

Re: Newbie question: how can I list added files?

Bruce Korb <bruce.korb@gmail.com> writes:
Show 8 quoted lines
> $ git diff --name-only HEAD
> chip/chopin2/up/hdl/.sopc_builder/install.ptf
> chip/mozart/up_oam/hdl/.sopc_builder/install.ptf
> chip/mozart2/up/hdl/.sopc_builder/install.ptf
> chip/mozart2/up_ft/hdl/.sopc_builder/install.ptf
> sw/embedded/nios2/system/system.stf
> sw/embedded/platform/strad/scripts/mk_relsrc.sh
> sw/projects/nios2/modules/system/lib/system.stf
Try using --name-status instead here and check what you see.
Jeff King· Jun 23, 2010, 18:30 UTC · re: Bruce Korb · lore

Re: Newbie question: how can I list added files?

On Wed, Jun 23, 2010 at 10:50:11AM -0700, Bruce Korb wrote:
Show 23 quoted lines
> On Wed, Jun 23, 2010 at 10:43 AM, Junio C Hamano <gitster@pobox.com> wrote:
> > "git diff --name-only --diff-filter=A HEAD"?
> 
> Thank you, but "Nope."
> My added file doesn't show anything and not using the
> "--diff-filter" thing shows both added and not added files:
> 
> $ git diff --name-only --diff-filter=A HEAD
> $ git-status
> # On branch master
> # Changes to be committed:
> #   (use "git reset HEAD <file>..." to unstage)
> #
> #       modified:   sw/embedded/platform/strad/scripts/mk_relsrc.sh
> [...]
> $ git diff --name-only HEAD
> chip/chopin2/up/hdl/.sopc_builder/install.ptf
> chip/mozart/up_oam/hdl/.sopc_builder/install.ptf
> chip/mozart2/up/hdl/.sopc_builder/install.ptf
> chip/mozart2/up_ft/hdl/.sopc_builder/install.ptf
> sw/embedded/nios2/system/system.stf
> sw/embedded/platform/strad/scripts/mk_relsrc.sh
> sw/projects/nios2/modules/system/lib/system.stf

Usually when we say "added file", it means "a new file which has just been added". Did you mean "a file which was modified, but whose contents I have already added to the index"?

In that case, I think you just want:
  git diff --cached --name-only

to see files that differ between the index and HEAD (i.e., things which will be committed).

-Peff
Bruce Korb· Jun 23, 2010, 19:15 UTC · re: Jeff King · lore

Re: Newbie question: how can I list added files?

On Wed, Jun 23, 2010 at 11:30 AM, Jeff King <peff@peff.net> wrote:
Show 25 quoted lines
> On Wed, Jun 23, 2010 at 10:50:11AM -0700, Bruce Korb wrote:
>
>> On Wed, Jun 23, 2010 at 10:43 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> > "git diff --name-only --diff-filter=A HEAD"?
>>
>> Thank you, but "Nope."
>> My added file doesn't show anything and not using the
>> "--diff-filter" thing shows both added and not added files:
>>
>> $ git diff --name-only --diff-filter=A HEAD
>> $ git-status
>> # On branch master
>> # Changes to be committed:
>> #   (use "git reset HEAD <file>..." to unstage)
>> #
>> #       modified:   sw/embedded/platform/strad/scripts/mk_relsrc.sh
>> [...]
>> $ git diff --name-only HEAD
>> chip/chopin2/up/hdl/.sopc_builder/install.ptf
>> chip/mozart/up_oam/hdl/.sopc_builder/install.ptf
>> chip/mozart2/up/hdl/.sopc_builder/install.ptf
>> chip/mozart2/up_ft/hdl/.sopc_builder/install.ptf
>> sw/embedded/nios2/system/system.stf
>> sw/embedded/platform/strad/scripts/mk_relsrc.sh
>> sw/projects/nios2/modules/system/lib/system.stf
Hello,
"--name-status" just adds "M" in front of that list.
> Usually when we say "added file", it means "a new file which has just
> been added". Did you mean "a file which was modified, but whose contents
> I have already added to the index"?

I mean a file that was "git add"-ed and thus is now staged. One would first guess that "git-ls-files --stage" would get what I want, but no, it lists every file in the repo. Not what I need.

Show 6 quoted lines
> In that case, I think you just want:
>
>  git diff --cached --name-only
>
> to see files that differ between the index and HEAD (i.e., things which
> will be committed).
*YES*  That *IS* what I want.  Thank you!!!  Regards, Bruce

P.S. Is it really so rare that someone would want this info that it should wind up being so obscure? I now have a new alias:

   alias git-ls-staged="git diff --cached --name-only"
Eric Raible· Jun 23, 2010, 19:52 UTC · re: Bruce Korb · lore

Re: Newbie question: how can I list added files?

Bruce Korb <bruce.korb <at> gmail.com> writes:
> P.S. Is it really so rare that someone would want this info that it should
> wind up being so obscure?  I now have a new alias:
> 
>    alias git-ls-staged="git diff --cached --name-only"
Both: gitk and "git gui" show this quite clearly.
Tomas Carnecky· Jun 23, 2010, 19:55 UTC · re: Bruce Korb · lore

Re: Newbie question: how can I list added files?

On 6/23/10 9:15 PM, Bruce Korb wrote:
> P.S. Is it really so rare that someone would want this info that it should
> wind up being so obscure?  I now have a new alias:
> 
>    alias git-ls-staged="git diff --cached --name-only"
Did you know git has a builtin support for aliases?
  $ git config --global alias.ls-staged "diff --cached --name-only"
tom
Andreas Schwab· Jun 23, 2010, 20:04 UTC · re: Bruce Korb · lore

Re: Newbie question: how can I list added files?

Bruce Korb <bruce.korb@gmail.com> writes:
>    alias git-ls-staged="git diff --cached --name-only"
Or: git config alias.ls-staged "diff --cached --name-only"
(Perhaps add --global.)
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

← back to recent threads