# Newbie question: how can I list added files?

9 messages from 2010-06-23 to 2010-06-23. Participants: Bruce Korb, Junio C Hamano, Jeff King, Eric Raible, Andreas Schwab, Tomas Carnecky.
Thread: https://gitlist.dev/t/24174

## Bruce Korb, 2010-06-23 17:31

Subject: Newbie question: how can I list added files?
Message-ID: <AANLkTinxOE5xcP_V-PvoZGlfsxtcCafoYKy_PuBZnQnQ@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinxOE5xcP_V-PvoZGlfsxtcCafoYKy_PuBZnQnQ%40mail.gmail.com

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

```

## Junio C Hamano, 2010-06-23 17:43

Subject: Re: Newbie question: how can I list added files?
Message-ID: <7vzkylejbf.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzkylejbf.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTinxOE5xcP_V-PvoZGlfsxtcCafoYKy_PuBZnQnQ@mail.gmail.com>

```
"git diff --name-only --diff-filter=A HEAD"?

```

## Bruce Korb, 2010-06-23 17:50

Subject: Re: Newbie question: how can I list added files?
Message-ID: <AANLkTikE2ylLXk5XxNGvcvol6R-puSTzPurdLcNMYaZJ@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikE2ylLXk5XxNGvcvol6R-puSTzPurdLcNMYaZJ%40mail.gmail.com
In-Reply-To: <7vzkylejbf.fsf@alter.siamese.dyndns.org>

```
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, 2010-06-23 18:28

Subject: Re: Newbie question: how can I list added files?
Message-ID: <7vvd99eh8l.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vvd99eh8l.fsf%40alter.siamese.dyndns.org
In-Reply-To: <AANLkTikE2ylLXk5XxNGvcvol6R-puSTzPurdLcNMYaZJ@mail.gmail.com>

```
Bruce Korb <bruce.korb@gmail.com> writes:

> $ 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, 2010-06-23 18:30

Subject: Re: Newbie question: how can I list added files?
Message-ID: <20100623183050.GA20842@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20100623183050.GA20842%40coredump.intra.peff.net
In-Reply-To: <AANLkTikE2ylLXk5XxNGvcvol6R-puSTzPurdLcNMYaZJ@mail.gmail.com>

```
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

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, 2010-06-23 19:15

Subject: Re: Newbie question: how can I list added files?
Message-ID: <AANLkTin-MEBUYheTkFbeKIBj5peVV-sPa7hZSg-wMgBi@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTin-MEBUYheTkFbeKIBj5peVV-sPa7hZSg-wMgBi%40mail.gmail.com
In-Reply-To: <20100623183050.GA20842@coredump.intra.peff.net>

```
On Wed, Jun 23, 2010 at 11:30 AM, Jeff King <peff@peff.net> wrote:
> 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.

> 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, 2010-06-23 19:52

Subject: Re: Newbie question: how can I list added files?
Message-ID: <loom.20100623T214603-16@post.gmane.org>
URL: https://gitlist.dev/e/loom.20100623T214603-16%40post.gmane.org
In-Reply-To: <AANLkTin-MEBUYheTkFbeKIBj5peVV-sPa7hZSg-wMgBi@mail.gmail.com>

```
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, 2010-06-23 19:55

Subject: Re: Newbie question: how can I list added files?
Message-ID: <4C2266B4.2060404@dbservice.com>
URL: https://gitlist.dev/e/4C2266B4.2060404%40dbservice.com
In-Reply-To: <AANLkTin-MEBUYheTkFbeKIBj5peVV-sPa7hZSg-wMgBi@mail.gmail.com>

```
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, 2010-06-23 20:04

Subject: Re: Newbie question: how can I list added files?
Message-ID: <m2aaqlh5wx.fsf@igel.home>
URL: https://gitlist.dev/e/m2aaqlh5wx.fsf%40igel.home
In-Reply-To: <AANLkTin-MEBUYheTkFbeKIBj5peVV-sPa7hZSg-wMgBi@mail.gmail.com>

```
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."

```
