2014-07-26 29 views
1

跟着Version Control with Git 2nd ed,沒有得到與本書相同的結果。我錯過了什麼嗎?這是本書的例子。.gitignore上的不同結果

$ cd /tmp/my_stuff 
$ git init 
$ git status 
# On branch master 
# 
# Initial commit 
# 
nothing to commit (create/copy files and use "git add" to track) 
$ echo "New data" > data 
$ git status 
# On branch master 
# 
# Initial commit 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# data 
nothing added to commit but untracked files present (use "git add" to track) 


# Manually create an example junk file 
$ touch main.o 
$ git status 
# On branch master 
# 
# Initial commit 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# data 
# main.o 
$ echo main.o > .gitignore 
$ git status 
# On branch master 
# 
# Initial commit 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# .gitignore 
# data 

但對我來說echo main.o > .gitignore後,git status是顯示main.o不會被忽略,並呈現出在未跟蹤文件。

編輯:在這個例子中沒有提交所以git rm -r --cached .,給我fatal: pathspec '.' did not match any files。我也曾嘗試commiting data,並main.o,然後

>>touch .gitignore 
>>git rm -r --cached . 
>>git add . 
>>git commit -m ".gitignore is stil not ignoring main.o" 
+0

嘗試清理項目的緩存。 'git rm -r --cached .' –

+1

請顯示'.gitignore'文件內容 –

+0

'$ echo main.o> .gitignore'正在創建'.gitingore'作爲文件內容'main.o'。我也編輯了問題,以反映我到目前爲止所嘗試的內容。 –

回答

0

確保.gitignore是在同一水平main.o創建的,沒有錯字(your comment,例如,提到的.gitingore代替.gitignore

如果main.o沒有被添加(沒有git add),效果將是瞬時的(不需要甚至將.gitignore添加到索引或提交它):main.o文件將在下一個git status調用中被忽略。

確保「main.o」沒有尾隨空格在其名稱(「name.o」),或嘗試在.gitignore使用更多的全球模式,看看是否有任何影響:

*.o 
*.o*