2013-03-24 81 views
4

我正在使用Git創建備份系統。GIT - git-add錯誤(錯誤文件號)

我剛剛創建了目錄並初始化了它。

git init 

當我試圖未跟蹤文件與

git add -u *.pdf 

我得到這個響應錯誤添加到舞臺:

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

至於更多的信息,我有一個列表〜4500未跟蹤的文件,如果我嘗試逐個添加文件,我不會收到任何錯誤響應,並將文件發送到舞臺。

有誰知道如何解決這個問題,爲什麼會發生?我需要添加所有這些未跟蹤的文件,但我不想以「猴子工作」的方式做到這一點,逐個添加。

+0

我其實犯了一個愚蠢的錯誤。我編寫了git-add命令,而不用單引號括住通配符。就像@GoZoner說的,我誤解了選項'-u'的含義。 – luisfsns 2013-03-24 03:06:44

回答

6

你不想'-u',因爲它只會添加你已經跟蹤的文件。在git init之後,你還沒有追蹤任何東西。從文檔:

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

使用-A(或--all)來代替。

對於您的特定問題,當您編寫'* .pdf'時,shell會將其擴展爲4500個文件。大量文件可能會溢出shell命令行輸入緩衝區;這導致錯誤。你可以做幾件事情:

git add -A    # adds everything at once 

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

這兩項建議將避免在命令行中的問題;第一個是首選。

+0

請添加選中標記並加入! – GoZoner 2013-03-24 02:39:45

+1

我其實犯了一個愚蠢的錯誤。我編寫了git-add命令,而不用單引號括住通配符。問題不是溢出¬¬。 但你的解釋是非常有幫助的! 我是Git的新手。對不起,浪費你的時間。今天我剛剛開始閱讀並瞭解它(http://git-scm.com/book/en/) 非常感謝巴西! – luisfsns 2013-03-24 02:53:24

+1

我不能添加加票,我沒有足夠的聲望。我需要至少15分。但是當我得到他們,我回到這裏給你投票。 謝謝 – luisfsns 2013-03-24 02:55:14