參考網址http://blog.csdn.net/richardysteven/article/details/6069418
具體使用請看 man gitignore
一般某個項目dev過程中都會產生一些中間文件,這些文件是我們不想要追蹤的。
git中可以使用.gitignore文件來忽略這些文件。
在需要的目錄下面 添加 .gitignore文件
文件中每一行表示需要忽略的文件的正則表達式。
$cat .gitignore
#ignore .metadata
.metadata
.gitignore
#ignore obj and lib file
*.[oa]
當前的目錄情況
$ls -al
total 24
drwxr-xr-x 4 root root 4096 2010-12-11 12:44 .
drwx------ 51 root root 4096 2010-12-11 12:44 ..
drwxr-xr-x 8 root root 4096 2010-12-11 12:44 .git
-rw-r--r-- 1 root root 39 2010-12-11 12:44 .gitignore
drwxr-xr-x 3 root root 4096 2010-08-19 20:01 .metadata
-rw-r--r-- 1 root root 52 2010-12-11 12:41 test.txt
如果沒有添加該文件,git status會報有這些文件沒有track。
$git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .metadata/
# gitignore
而 添加了該文件後,就可以看到,這個workspace 就是乾淨的了。
$mv gitignore .gitignore
[root@~/workspace]
$git status
# On branch master
nothing to commit (working directory clean)
這個.gitignore很簡單,當前目錄下有個.metadata,這個是我們不需要的,所以就寫入了文件。另外如果不加.gitignore這行,git會把.gitignore也加入版本控制中。