4

I'm using Git to create a backup system.

I've just created the directory and initialized git on it.

git init

When I tried to add the untracked files to the stage with

git add -u *.pdf

I get this response error:

sh.exe": /bin/git: Bad file number

As additional information, I have a list of ~4500 untracked files and if I try to add the files one by one, I don't get any error response and the files are sent to the stage.

Does anyone know how to solve this problem and why it happens? I need to add all these untracked files, but I don't want to do that in a "monkey job" way, adding one by one.

luisfsns
  • 81
  • 1
  • 6
  • I actually had made a dumb mistake. I'd written the git-add command without surrounding the wildcard with single quotes. And like @GoZoner said, I had misunderstood the meaning of the option '-u'. – luisfsns Mar 24 '13 at 03:06

1 Answers1

6

You don't want '-u' as it will only add files that you are already tracking. After a git init you are not tracking anything yet. From the documentation:

-u, --update: Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.

Use -A (or --all) instead.

For your specific problem, when you write '*.pdf' the shell expands that into 4500 files. That large number of files probably overflows the shell command line input buffer; which leads to the error. You could do a few things:

git add -A               # adds everything at once

or

for file in *.pdf; do git add -A $file; done    # add files one by one

Both of these suggestions will avoid the command line issue; the first is preferred.

GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • 1
    I actually had made a dumb mistake. I'd written the git-add command without surrounding the wildcard with single quotes. The problem was not overflow ¬¬. But your explanation was very helpful! I'm a newbie on Git. Sorry for wasting your time. I've just started to read and learn about it, today (http://git-scm.com/book/en/) Many thanks from Brazil! – luisfsns Mar 24 '13 at 02:53
  • 1
    I can't add an up-vote, I don't have enough reputation. I need at least 15 points. But when i get them, I return here and give you the vote. Thanks – luisfsns Mar 24 '13 at 02:55
  • If you pass `*.pdf` to `git add` then git will expand the `*` and won't overflow. If you skip the quotes, then the shell will expand `*` and overflow. – GoZoner Mar 24 '13 at 04:31
  • Sorry, but what do you mean by saying "expand"? – luisfsns Mar 24 '13 at 19:27
  • 'Expand' means replacing '*.pdf' with all the matching files, like 'foo.pdf bar.pdf ...' – GoZoner Mar 24 '13 at 20:00