threads / discuss / 37986

Doing a git add '' will add more files then expected

Subject: Doing a git add '' will add more files then expected

## tl;dr

5 messages between Nov 17, 2014 and Nov 23, 2014.

replies: 4people: 5as markdown or json

Guilherme· Nov 17, 2014, 16:25 UTC · lore
Hello,

I first asked on stackoverflow (http://stackoverflow.com/questions/26933761/python-sh-module-and-git-try-to-add-more-files-then-in-command/26934517#26934517) about this behaviour.

Then on the conversation that happened on the git-users mailing list other agreed that this behaviour is probably not as intended.

Steps to reproduce: In bash (not sure this is bash specific) do: git add '' (that's to apostrophes, an empty argument)

Results same as doing git add .

Expected no files added or error about not finding file ''

Hope this helps. Guilherme

Andreas Schwab· Nov 17, 2014, 18:15 UTC · re: Guilherme · lore

Re: Doing a git add '' will add more files then expected

Guilherme <guibufolo@gmail.com> writes:
Show 10 quoted lines
> Steps to reproduce:
> In bash (not sure this is bash specific) do:
> git add ''
> (that's to apostrophes, an empty argument)
>
> Results
> same as doing git add .
>
> Expected
> no files added or error about not finding file ''

The argument to git add is a pathspec, and the empty pathspec matches all files.

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."
Matthieu Moy· Nov 17, 2014, 18:42 UTC · re: Andreas Schwab · lore

Re: Doing a git add '' will add more files then expected

Andreas Schwab <schwab@linux-m68k.org> writes:
> The argument to git add is a pathspec, and the empty pathspec matches
> all files.
Err, why does the empty pathspec match all files? Isn't that a bug?
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Junio C Hamano· Nov 17, 2014, 19:08 UTC · re: Matthieu Moy · lore

Re: Doing a git add '' will add more files then expected

Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> writes:
Show 6 quoted lines
> Andreas Schwab <schwab@linux-m68k.org> writes:
>
>> The argument to git add is a pathspec, and the empty pathspec matches
>> all files.
>
> Err, why does the empty pathspec match all files? Isn't that a bug?
That is debatable.
    cd Documentation
    git add "a"
would be equivalent to typing
    git add Documentation/"a"
so
    cd Documentation
    git add ""
would be equivalent to typing
    git add Documentation/""

And doing the same from the top-level of the working tree can be argued to be a natural extension.

Javier Domingo Cansino· Nov 23, 2014, 19:06 UTC · re: Junio C Hamano · lore

Re: Doing a git add '' will add more files then expected

IMO, if you put an empty string "" you would be implying the same as with a dot (git add . ).

The important thing is that "git add" without a pathspec returns an error, as it has always done, mainly because it people tend to work without gitignoring all the files they should, and allowing such behaviour would make things harder.

-- 
Javier Domingo Cansino

← back to recent threads