2012-11-12 76 views
8

當我嘗試添加的git我的文件,我輸入Git的添加不添加文件

git add <insert file names here> 

這正常工作。但是,當我嘗試做

git commit -a 

我的git存儲庫告訴我它是空的。輸出是:

# On branch master 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
<insert name of files here> 

nothing added to commit but untracked files present (use "git add" to track) 

可能有人知道這個解決方案嗎?謝謝。

+2

它也可能已經是一個跟蹤文件。 – meawoppl

回答

5

-a標誌爲git commit會覆蓋您的暫存區域(「索引」)。看看手冊頁說的話:

-a, --all 
     Tell the command to automatically stage files that have been modified 
     and deleted, but new files you have not told git about are not 
     affected. 

一條經驗法則是使用純git commit當你使用git add。命令git commit -a適用於您想要提交存儲庫中的每個更改,但不能打擾到git add這些更改。

PS。 git add -A非常有用:它在您的工作樹中添加了所有未被忽略的新文件

+0

我一定會喜歡吃我的蛋糕並同時吃它¯\\ _(ツ)_ /¯ – Chris

16

而且您可能還想確保您位於項目的根目錄中。我在一段時間內在Rails項目上遇到了這個問題&然後意識到我在/config目錄中。哎呦! #noobmistake

+2

Git可以在git工作樹的任何地方工作。 。 。 – meawoppl

+2

@meawoppl它從來沒有我以前,但我欣賞downvote! –

+2

@meawoppl號Git理論上來自任何地方,但'git add --all'可能不會!我認爲這是因爲它相當於'git add .'(http://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add),因此只適用於當前和子目錄。如果你對這個主題有足夠的知識,請只做downvote ... –